Why does my call from a Java event handler to Mathematica hang?
 Whenever you call into Mathematica from the Java user interface thread, you must call StdLink.requestTransaction() to await permission to proceed. See the User Guide section Part 1 → Writing Your Own Installable Java Classes → Writing Your Own Event Handler Code, concerning this issue. It is always safe to use the idiom StdLink.requestTransaction(); synchronized (ml) { ... use the link ... } In Java code that calls Mathematica, it is recommended that you do this in the class that calls Mathematica. StdLink.requestTransaction() is only necessary in one case: Java has been launched by Mathematica via InstallJava, and you are not in the middle of a call from Mathematica into Java. The typical case where these requirements are met is where a user action in Java is triggering a call into Mathematica. However, StdLink.requestTransaction() is safe to call even when these requirements are not met. In other words, it is a no-op in cases where it is not necessary. So for code like yours that needs to be very general because it might be called in lots of different circumstances you should always use the idiom above and call StdLink.requestTransaction() followed by locking the link. Download this FAQ as a Mathematica 5.2 Notebook
Questions or comments? Send email to support@wolfram.com.
|