Hi, not sure if this is the right place to post this problem but since it is related to javax.Persistence, this looks to be the most appropriate category. I have a very strange problem that I do not know how to solve. I have an application that creates a thread, does something, and then calls another application:

App1 --- thread 1 ----> does something ----> Finish
|---- thread 2 ----> does something ----> calls App2 ----> Finish

Now in App2, it has the following code:

System.out.println("here 1");
em = emfUser.createEntityManager();
System.out.println("here 2");

Scenario 1 - running App2 by itself

If I run App2 by itself (App1 does not call App2), then the above code executes perfectly fine. No problem there.

Scenario 2 - calling App2 through App1

However, if I invoke App2 from App1 by:

Process pr = Runtime.getRuntime().exec(App2);

Then I get "here 1" but does not get to "here 2" UNLESS I kill App1 whether by task manager or stopping the ide. As soon as App1 is killed, it goes through createEntityManager() and then "here 2" is printed. And no exception is thrown by createEntityManager() because as soon as App1 is killed, the method continues on its merry way.

Please note that App1 does not do anything to the database. It has no database related tasks.

In production, App2 does need to be invoked by App1 so the simple solution of calling App2 by itself is not possible.

I would really appreciate some help on this as I am at my wit's end. The tasks that App1 does is totally unrelated to App2 so I have no idea why App2 is stuck at createEntityManager() when invoked by App1.