OFBiz中JOB的运行机制
http://www.cnblogs.com/Ivan-j2ee/archive/2012/04/13/2445421.html OFBiz执行后台任务的类在org.ofbiz.service.job中。
1
public
synchronized
void
run() {
2 try { 3 // wait 30 seconds before the first poll 4 java.lang.Thread.sleep( 30000 ); 5 } catch (InterruptedException e) { 6 } 7 while (isRunning) { 8 try { 9 // grab a list of jobs to run. 10 List < Job > pollList = jm.poll(); 11 // Debug.logInfo("Received poll list from JobManager [" + pollList.size() + "]",module); 12 13 for (Job job : pollList) { 14 if (job.isValid()) { 15 queueNow(job); 16 // Debug.logInfo("Job [" + job.getJobId() + "] is queued",module); 17 } 18 } 19 // NOTE: using sleep instead of wait for stricter locking 20 java.lang.Thread.sleep(pollWaitTime()); 21 } catch (InterruptedException e) { 22 Debug.logError(e,module); 23 stop(); 24 } 25 } 26 } 27
1
public
void
queueNow(Job job) {
2 synchronized (run) { 6 run.add(job); 7 } 8 if (Debug.verboSEOn()) Debug.logVerbose( " New run queue size: " + run.size(),module); 9 if (run.size() > pool.size() && pool.size() < maxThreads()) { 10 synchronized (pool) { 11 if (run.size() > pool.size() && pool.size() < maxThreads()) { 12 int calcSize = (run.size() / jobsPerThread()) - (pool.size()); 13 int addSize = calcSize > maxThreads() ? maxThreads() : calcSize; 14 15 for ( int i = 0 ; i < addSize; i ++ ) { 16 JobInvoker iv = new JobInvoker( this ,invokerWaitTime()); 17 pool.add(iv); 18 } 19 } 20 } 21 } 22 }
1
public
void
exec()
throws
InvalidJobException {
2 init(); 3 4 // no transaction is necessary since runSync handles this 5 try { 6 // get the dispatcher and invoke the service via runSync -- will run all ECAs 7 LocalDispatcher dispatcher = dctx.getDispatcher(); 8 Map < String,Object > result = dispatcher.runSync(getServiceName(),getContext()); 9 10 // check for a failure 11 boolean isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE)); 12 if (isError) { 13 String errorMessage = (String) result.get(ModelService.ERROR_MESSAGE); 14 this .failed( new Exception(errorMessage)); 15 } 16 17 if (requester != null ) { 18 requester.receiveResult(result); 19 } 20 21 } catch (Throwable t) { 22 // pass the exception back to the requester. 23 if (requester != null ) { 24 requester.receiveThrowable(t); 25 } 26 27 // call the failed method 28 this .failed(t); 29 } 30 31 // call the finish method 32 this .finish(); 33 } 34
1
TemporalExpression expr
=
null
;
2 …… 3 4 if (expr == null && UtilValidate.isNotEmpty(job.getString( " tempExprId " ))) { 5 try { 6 expr = TemporalExpressionWorker.getTemporalExpression( this .delegator,job.getString( " tempExprId " )); 7 } catch (GenericEntityException e) { 8 throw new RuntimeException(e.getMessage()); 9 } 10 } 11
仅供个人收藏 转载自:http://www.blogjava.net/persister/archive/2010/02/26/313974.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |