aspose file tools*
The moose likes Other Languages and the fly likes running a script within Java: pause/resume needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "running a script within Java: pause/resume needed" Watch "running a script within Java: pause/resume needed" New topic
Author

running a script within Java: pause/resume needed

Maurice Manning
Greenhorn

Joined: Nov 15, 2006
Posts: 2
I do understand that that pause/resume are deprecated, I am using a pattern described here: http://www.cs.wisc.edu/~cs368-1/JavaTutorial/jdk1.2/guide/misc/threadPrimitiveDeprecation.html. The script language I would like to use is Python but I am flexible.

The script will move a robot arm as well as control a sensor device and a camera by calling a Java API for the deveices. The user may need to stop the process if there are problems with the hardware or some items (cleaning basin, fluids) were not correctly prepared. I have the client/server set up as a web service and the script is passed in the envelope. My Manager class then spins off a thread for a ScriptRunner class which contains the script to evaluate. This scriptrunner class contains the halt/pause/resume methods which are patterned after the article. The Manager can receive the pause command from the client and relay it to the ScriptRunner class. My classes are wired together with the Spring framework. The problem is that when I call jythonInterpreter.exec(thisScript), that creates a separate thread that I do not have access to. I also tried javascript/Rhino (which I do not like) because it looked like it shared the same thread as the class which spawns it but I was not successful in getting the pause/resume to work.

I do not want the script to have to contain a bunch of code that checks if the thread has paused or halted, I would like it to only contain commands to run the robot. I need each instruction (moveRobotArm(vector))to execute atomically. (No database interaction, btw) I need loops and control structures; otherwise I could just exec each Python statement in the script separately within my ScriptRunner run loop. From the Python docs:

�The design of this module is loosely based on Java's threading model. However, where Java makes locks and condition variables basic behavior of every object, they are separate objects in Python. Python's Thread class supports a subset of the behavior of Java's Thread class; currently, there are no priorities, no thread groups, and threads cannot be destroyed, stopped, suspended, resumed, or interrupted. The static methods of Java's Thread class, when implemented, are mapped to module-level functions.�

If you are still reading, I am amazed. I would be interested in any ideas on design options. Thanks again for your interest/response.

Mo
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Please post your question in just one forum. Followups here. Thank you.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running a script within Java: pause/resume needed