[jboss-user] [jBPM] - Re: Error "Timeout trying to lock table 'PROCESSINSTANCELOG'"

Massimiliano Izzo do-not-reply at jboss.com
Mon Jun 3 13:02:19 EDT 2013


Massimiliano Izzo [https://community.jboss.org/people/amizzo] created the discussion

"Re: Error "Timeout trying to lock table 'PROCESSINSTANCELOG'""

To view the discussion, visit: https://community.jboss.org/message/821060#821060

--------------------------------------------------------------
Finally I understood why we receive this error.
The script task should not sleep. If you need to process some time consuming task, you should register your own workitemhandler (through the session.template file).

Something like the following:



public class MizzoTaskHandler  implements WorkItemHandler {
  private WorkItemManager workItemManager;
  private WorkItem workItem;
  private long workItemId;
  private Map results;
  private StatefulKnowledgeSession ksession;


  public MizzoTaskHandler(StatefulKnowledgeSession ksession){
    this.ksession = ksession;
  }

  public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    this.workItemId = workItem.getId();
    this.workItemManager = workItemManager;
    this.workItem = workItem;
    System.out.println("exec:" + workItemId);
    results = new HashMap();
    Thread th=new Thread(){
      public void run(){
        results.put("testWH",testleggiQ());
        ksession.getWorkItemManager().completeWorkItem(workItemId,results);
      }
    };
    th.start();
  }


  public void abortWorkItem(WorkItem workItem, WorkItemManager workItemManager) {


  }


  public void completeWorkItem() {
    workItemManager.completeWorkItem(workItemId, results);
  }
  public static String testleggiQ() {
    QueueConnection jmsConnection = null;
    QueueSession jmsSession = null;
    MessageConsumer receiver = null;
    try {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");


      env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");


      InitialContext iniCtx = new InitialContext(env);
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory tcf = (QueueConnectionFactory)tmp;
      jmsConnection = tcf.createQueueConnection();


      // jmsConnection.setClientID((String)contextResources.get("JMS_CLIENT_ID"));
      Queue qu = (Queue)iniCtx.lookup("queue/testQIn");
      jmsSession = jmsConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      receiver = jmsSession.createConsumer(qu);
      jmsConnection.start();
      TextMessage msg = (TextMessage)receiver.receive();


      return msg.getText();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    finally {
      try {
        if (receiver != null)
          receiver.close();
        if (jmsSession != null)
          jmsSession.close();
        if (jmsConnection != null)
          jmsConnection.close();
      }
      catch (Exception ex2) {
        ex2.printStackTrace();
      }
    }
    return "";
  }
}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/821060#821060]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130603/9d3a047d/attachment-0001.html 


More information about the jboss-user mailing list