<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JobExecutor thread DataSource usage in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75066#M49284</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The jobexecutor uses commands like any other api call, so it should just use the same datasource.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you paste a log or something that illustrates the problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Jul 2011 07:45:08 GMT</pubDate>
    <dc:creator>jbarrez</dc:creator>
    <dc:date>2011-07-07T07:45:08Z</dc:date>
    <item>
      <title>JobExecutor thread DataSource usage</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75065#M49283</link>
      <description>Hi,I'm currently specifying the DataSource that a process engine should use via the ProcessEngineConfiguration.setDataSource() call (prior to calling setJobExecutorActivate(true)).&amp;nbsp; This works fine in the process engine case.&amp;nbsp; However, when the job executor thread executes, it appears to be obtainin</description>
      <pubDate>Tue, 05 Jul 2011 18:47:31 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75065#M49283</guid>
      <dc:creator>bwd</dc:creator>
      <dc:date>2011-07-05T18:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: JobExecutor thread DataSource usage</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75066#M49284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The jobexecutor uses commands like any other api call, so it should just use the same datasource.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you paste a log or something that illustrates the problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 07:45:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75066#M49284</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2011-07-07T07:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: JobExecutor thread DataSource usage</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75067#M49285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I got things to work, but it seems sub-optimal.&amp;nbsp; Here are more details:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We're using Activiti in a multi-tenant environment where multiple process engines are running in a single app server, each talking to a separate database account.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is accomplished by calling setDataSource() with a tenant-specific data source on the ProcessEngineConfiguration, prior to calling buildProcessEngine() against it to create the new process engine.&amp;nbsp; This seems to work fine - each engine talks to a separate database for all of it's operations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, when job executor activation was enabled, it doesn't appear to use the data source set for the process engine.&amp;nbsp; It appears to be using a data source configured in Spring (which doesn't work in our case, as it doesn't know which tenant it's working with).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's how I finally got things to work (The approach was taken based on an examination of the org.activiti.engine.impl.jobexecutor.JobExecutor code - start() method in particular):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Created a new class that extends JobAcquisitionThread.&amp;nbsp; This class re-implements the run() method to set up the correct data source and then call super.run().&amp;nbsp; This class is instantiated with an externally-created JobExecutor, which is then passed to the ProcessEngineConfiguration via a setJobExecutor() call.&amp;nbsp; This allowed the available-jobs-query to query against the correct database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Create a new class that extends ThreadPoolExecutor that implements beforeExecute() and afterExecute() to set up and tear-down the appropriate data source prior to actual job execution.&amp;nbsp; An instance of this class was set on the JobExecutor instance described above via a call to setThreadPoolExecutor().&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Once this was done, the background threads started using the correct data source.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In our non-Activiti code, we support multi-tenancy by having a Spring-configured custom DataSource that is implemented via a map of database-specific data sources, keyed by tenant-id.&amp;nbsp; this tenant-id is set as a thread local variable when a request comes in from a specific tenant, allowing all subsequent code to get a data source for the correct database without having to explicitly specify the tenant identifier.&amp;nbsp; The background job processing threads appeared to be using this data source, but the tenant-id thread local variable wasn't set in this case (obviously), so the job threads were getting the incorrect data source.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideally - unless i'm misunderstanding something - all Activiti code would use any data source set on the configuration object used to contruct the engine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BWD&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 16:49:52 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/jobexecutor-thread-datasource-usage/m-p/75067#M49285</guid>
      <dc:creator>bwd</dc:creator>
      <dc:date>2011-07-07T16:49:52Z</dc:date>
    </item>
  </channel>
</rss>

