Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.06 KB | None | 0 0
  1. // 1) this is fine
  2.     public void start(final RuntimeManager manager){
  3. ExecutorService exec = Executors.newCachedThreadPool();
  4.        
  5.         exec.submit(new Runnable(){
  6.             @Override
  7.             public void run() {
  8.                 // start a new process instance
  9.                 RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
  10.                 KieSession ksession = runtimeEngine.getKieSession();
  11.                 Map<String, Object> params = new HashMap<>();
  12.                 SupplyItem item1 = new SupplyItem();
  13.                 item1.setDescription("Red Shoes");
  14.                 params.put("supplyItem", item1);
  15.                 ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
  16.                
  17.                 System.out.println("Started process:" + proc.getId());
  18.                
  19.                
  20.                 RuntimeEngine runtimeEngine2 = manager.getRuntimeEngine(EmptyContext.get());
  21.                 KieSession ksession2 = runtimeEngine2.getKieSession();
  22.                 Map<String, Object> params2 = new HashMap<>();
  23.                 SupplyItem item2 = new SupplyItem();
  24.                 item2.setDescription("Red Hat");
  25.                 params.put("supplyItem", item2);
  26.                 ProcessInstance proc2 = ksession2.startProcess("com.example.bpms.simplesupplyitemapproval", params2);
  27.                
  28.                 System.out.println("Started process:" + proc2.getId());
  29.                
  30.                 //manager.disposeRuntimeEngine(runtimeEngine);
  31.             }
  32.         });
  33.  
  34. // 2) this fails
  35.     public void start(final RuntimeManager manager){
  36.         ExecutorService exec = Executors.newCachedThreadPool();
  37.        
  38.         exec.submit(new Runnable(){
  39.             @Override
  40.             public void run() {
  41.                 // start a new process instance
  42.                 RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
  43.                 KieSession ksession = runtimeEngine.getKieSession();
  44.                 Map<String, Object> params = new HashMap<>();
  45.                 SupplyItem item1 = new SupplyItem();
  46.                 item1.setDescription("Red Shoes");
  47.                 params.put("supplyItem", item1);
  48.                 ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
  49.                
  50.                 System.out.println("Started process:" + proc.getId());
  51.                
  52.                
  53. //              RuntimeEngine runtimeEngine2 = manager.getRuntimeEngine(EmptyContext.get());
  54. //              KieSession ksession2 = runtimeEngine2.getKieSession();
  55. //              Map<String, Object> params2 = new HashMap<>();
  56. //              SupplyItem item2 = new SupplyItem();
  57. //              item2.setDescription("Red Hat");
  58. //              params.put("supplyItem", item2);
  59. //              ProcessInstance proc2 = ksession2.startProcess("com.example.bpms.simplesupplyitemapproval", params2);
  60. //             
  61. //              System.out.println("Started process:" + proc2.getId());
  62.                
  63.                 manager.disposeRuntimeEngine(runtimeEngine);
  64.             }
  65.         });
  66.         exec.submit(new Runnable(){
  67.             @Override
  68.             public void run() {
  69.                 // start a new process instance
  70.                 RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
  71.                 KieSession ksession = runtimeEngine.getKieSession();
  72.                 Map<String, Object> params = new HashMap<>();
  73.                 SupplyItem item2 = new SupplyItem();
  74.                 item2.setDescription("Red Hat");
  75.                 params.put("supplyItem", item2);
  76.                 ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
  77.                
  78.                 System.out.println("Started process:" + proc.getId());
  79.                
  80.                 manager.disposeRuntimeEngine(runtimeEngine);
  81.             }
  82.         });
  83.        
  84.         exec.shutdown();
  85.         try {
  86.             exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
  87.         } catch (InterruptedException e) {
  88.             e.printStackTrace();
  89.         }
  90.  
  91.  
  92. Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY_KEY_C6 ON PUBLIC.ORGANIZATIONALENTITY(ID)"; SQL statement:
  93. insert into OrganizationalEntity (DTYPE, id) values ('User', ?) [23505-168]
  94.     at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
  95.     at org.h2.message.DbException.get(DbException.java:169)
  96.     at org.h2.message.DbException.get(DbException.java:146)
  97.     at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:81)
  98.     at org.h2.index.PageBtree.find(PageBtree.java:121)
  99.     at org.h2.index.PageBtreeLeaf.addRow(PageBtreeLeaf.java:147)
  100.     at org.h2.index.PageBtreeLeaf.addRowTry(PageBtreeLeaf.java:100)
  101.     at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:105)
  102.     at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:96)
  103.     at org.h2.index.MultiVersionIndex.add(MultiVersionIndex.java:50)
  104.     at org.h2.table.RegularTable.addRow(RegularTable.java:121)
  105.     at org.h2.command.dml.Insert.insertRows(Insert.java:124)
  106.     at org.h2.command.dml.Insert.update(Insert.java:84)
  107.     at org.h2.command.CommandContainer.update(CommandContainer.java:75)
  108.     at org.h2.command.Command.executeUpdate(Command.java:230)
  109.     at org.h2.server.TcpServerThread.process(TcpServerThread.java:328)
  110.     at org.h2.server.TcpServerThread.run(TcpServerThread.java:149)
  111.     at java.lang.Thread.run(Thread.java:744)
  112.  
  113.     at org.h2.engine.SessionRemote.done(SessionRemote.java:567)
  114.     at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:183)
  115.     at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
  116.     at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
  117.     at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
  118.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  119.     at java.lang.reflect.Method.invoke(Method.java:606)
  120.     at bitronix.tm.resource.jdbc.BaseProxyHandlerClass.invoke(BaseProxyHandlerClass.java:64)
  121.     at com.sun.proxy.$Proxy34.executeUpdate(Unknown Source)
  122.     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
  123.     ... 62 more
  124. Mar 26, 2015 9:59:47 AM org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl afterTransaction
  125. INFO: HHH000106: Forcing container resource cleanup on transaction completion
  126.  
  127. //3) this works too
  128.     public void start(final RuntimeManager manager){
  129.        
  130.         RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
  131.         KieSession ksession = runtimeEngine.getKieSession();
  132.         Map<String, Object> params = new HashMap<>();
  133.         SupplyItem item1 = new SupplyItem();
  134.         item1.setDescription("Red Shoes");
  135.         params.put("supplyItem", item1);
  136.         ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
  137.        
  138.  
  139.         ExecutorService exec = Executors.newFixedThreadPool(2);
  140.        
  141.         exec.submit(new Runnable(){
  142.             @Override
  143.             public void run() {
  144.                 // start a new process instance
  145.                 RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
  146.                 KieSession ksession = runtimeEngine.getKieSession();
  147.                 Map<String, Object> params = new HashMap<>();
  148.                 SupplyItem item1 = new SupplyItem();
  149.                 item1.setDescription("Red Shoes");
  150.                 params.put("supplyItem", item1);
  151.                 ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
  152.                
  153.                 System.out.println("Started process:" + proc.getId());
  154.                
  155.                
  156. //              RuntimeEngine runtimeEngine2 = manager.getRuntimeEngine(EmptyContext.get());
  157. //              KieSession ksession2 = runtimeEngine2.getKieSession();
  158. //              Map<String, Object> params2 = new HashMap<>();
  159. //              SupplyItem item2 = new SupplyItem();
  160. //              item2.setDescription("Red Hat");
  161. //              params.put("supplyItem", item2);
  162. //              ProcessInstance proc2 = ksession2.startProcess("com.example.bpms.simplesupplyitemapproval", params2);
  163. //             
  164. //              System.out.println("Started process:" + proc2.getId());
  165.                
  166.                 manager.disposeRuntimeEngine(runtimeEngine);
  167.             }
  168.         });
  169.         exec.submit(new Runnable(){
  170.             @Override
  171.             public void run() {
  172.                 // start a new process instance
  173.                 RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
  174.                 KieSession ksession = runtimeEngine.getKieSession();
  175.                 Map<String, Object> params = new HashMap<>();
  176.                 SupplyItem item2 = new SupplyItem();
  177.                 item2.setDescription("Red Hat");
  178.                 params.put("supplyItem", item2);
  179.                 ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
  180.                
  181.                 System.out.println("Started process:" + proc.getId());
  182.                
  183.                 manager.disposeRuntimeEngine(runtimeEngine);
  184.             }
  185.         });
  186.        
  187.         exec.shutdown();
  188.         try {
  189.             exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
  190.         } catch (InterruptedException e) {
  191.             e.printStackTrace();
  192.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement