Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1) this is fine
- public void start(final RuntimeManager manager){
- ExecutorService exec = Executors.newCachedThreadPool();
- exec.submit(new Runnable(){
- @Override
- public void run() {
- // start a new process instance
- RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession = runtimeEngine.getKieSession();
- Map<String, Object> params = new HashMap<>();
- SupplyItem item1 = new SupplyItem();
- item1.setDescription("Red Shoes");
- params.put("supplyItem", item1);
- ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
- System.out.println("Started process:" + proc.getId());
- RuntimeEngine runtimeEngine2 = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession2 = runtimeEngine2.getKieSession();
- Map<String, Object> params2 = new HashMap<>();
- SupplyItem item2 = new SupplyItem();
- item2.setDescription("Red Hat");
- params.put("supplyItem", item2);
- ProcessInstance proc2 = ksession2.startProcess("com.example.bpms.simplesupplyitemapproval", params2);
- System.out.println("Started process:" + proc2.getId());
- //manager.disposeRuntimeEngine(runtimeEngine);
- }
- });
- // 2) this fails
- public void start(final RuntimeManager manager){
- ExecutorService exec = Executors.newCachedThreadPool();
- exec.submit(new Runnable(){
- @Override
- public void run() {
- // start a new process instance
- RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession = runtimeEngine.getKieSession();
- Map<String, Object> params = new HashMap<>();
- SupplyItem item1 = new SupplyItem();
- item1.setDescription("Red Shoes");
- params.put("supplyItem", item1);
- ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
- System.out.println("Started process:" + proc.getId());
- // RuntimeEngine runtimeEngine2 = manager.getRuntimeEngine(EmptyContext.get());
- // KieSession ksession2 = runtimeEngine2.getKieSession();
- // Map<String, Object> params2 = new HashMap<>();
- // SupplyItem item2 = new SupplyItem();
- // item2.setDescription("Red Hat");
- // params.put("supplyItem", item2);
- // ProcessInstance proc2 = ksession2.startProcess("com.example.bpms.simplesupplyitemapproval", params2);
- //
- // System.out.println("Started process:" + proc2.getId());
- manager.disposeRuntimeEngine(runtimeEngine);
- }
- });
- exec.submit(new Runnable(){
- @Override
- public void run() {
- // start a new process instance
- RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession = runtimeEngine.getKieSession();
- Map<String, Object> params = new HashMap<>();
- SupplyItem item2 = new SupplyItem();
- item2.setDescription("Red Hat");
- params.put("supplyItem", item2);
- ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
- System.out.println("Started process:" + proc.getId());
- manager.disposeRuntimeEngine(runtimeEngine);
- }
- });
- exec.shutdown();
- try {
- exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY_KEY_C6 ON PUBLIC.ORGANIZATIONALENTITY(ID)"; SQL statement:
- insert into OrganizationalEntity (DTYPE, id) values ('User', ?) [23505-168]
- at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
- at org.h2.message.DbException.get(DbException.java:169)
- at org.h2.message.DbException.get(DbException.java:146)
- at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:81)
- at org.h2.index.PageBtree.find(PageBtree.java:121)
- at org.h2.index.PageBtreeLeaf.addRow(PageBtreeLeaf.java:147)
- at org.h2.index.PageBtreeLeaf.addRowTry(PageBtreeLeaf.java:100)
- at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:105)
- at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:96)
- at org.h2.index.MultiVersionIndex.add(MultiVersionIndex.java:50)
- at org.h2.table.RegularTable.addRow(RegularTable.java:121)
- at org.h2.command.dml.Insert.insertRows(Insert.java:124)
- at org.h2.command.dml.Insert.update(Insert.java:84)
- at org.h2.command.CommandContainer.update(CommandContainer.java:75)
- at org.h2.command.Command.executeUpdate(Command.java:230)
- at org.h2.server.TcpServerThread.process(TcpServerThread.java:328)
- at org.h2.server.TcpServerThread.run(TcpServerThread.java:149)
- at java.lang.Thread.run(Thread.java:744)
- at org.h2.engine.SessionRemote.done(SessionRemote.java:567)
- at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:183)
- at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
- at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
- at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:606)
- at bitronix.tm.resource.jdbc.BaseProxyHandlerClass.invoke(BaseProxyHandlerClass.java:64)
- at com.sun.proxy.$Proxy34.executeUpdate(Unknown Source)
- at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
- ... 62 more
- Mar 26, 2015 9:59:47 AM org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl afterTransaction
- INFO: HHH000106: Forcing container resource cleanup on transaction completion
- //3) this works too
- public void start(final RuntimeManager manager){
- RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession = runtimeEngine.getKieSession();
- Map<String, Object> params = new HashMap<>();
- SupplyItem item1 = new SupplyItem();
- item1.setDescription("Red Shoes");
- params.put("supplyItem", item1);
- ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
- ExecutorService exec = Executors.newFixedThreadPool(2);
- exec.submit(new Runnable(){
- @Override
- public void run() {
- // start a new process instance
- RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession = runtimeEngine.getKieSession();
- Map<String, Object> params = new HashMap<>();
- SupplyItem item1 = new SupplyItem();
- item1.setDescription("Red Shoes");
- params.put("supplyItem", item1);
- ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
- System.out.println("Started process:" + proc.getId());
- // RuntimeEngine runtimeEngine2 = manager.getRuntimeEngine(EmptyContext.get());
- // KieSession ksession2 = runtimeEngine2.getKieSession();
- // Map<String, Object> params2 = new HashMap<>();
- // SupplyItem item2 = new SupplyItem();
- // item2.setDescription("Red Hat");
- // params.put("supplyItem", item2);
- // ProcessInstance proc2 = ksession2.startProcess("com.example.bpms.simplesupplyitemapproval", params2);
- //
- // System.out.println("Started process:" + proc2.getId());
- manager.disposeRuntimeEngine(runtimeEngine);
- }
- });
- exec.submit(new Runnable(){
- @Override
- public void run() {
- // start a new process instance
- RuntimeEngine runtimeEngine = manager.getRuntimeEngine(EmptyContext.get());
- KieSession ksession = runtimeEngine.getKieSession();
- Map<String, Object> params = new HashMap<>();
- SupplyItem item2 = new SupplyItem();
- item2.setDescription("Red Hat");
- params.put("supplyItem", item2);
- ProcessInstance proc = ksession.startProcess("com.example.bpms.simplesupplyitemapproval", params);
- System.out.println("Started process:" + proc.getId());
- manager.disposeRuntimeEngine(runtimeEngine);
- }
- });
- exec.shutdown();
- try {
- exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement