|
CSP for Java (JCSP) 1.0-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jcsp.lang.ProcessNetwork
ProcessManager
.
This enables a CSProcess to be spawned concurrently with the process doing the spawning.
Parallel
network of processes to any depth of nesting.
This class is especially useful for managing a process network -- for example, in an Applet, where a convenient way to suspend execution is required for when the Applet is not on screen.
When a ProcessNetwork is not required any more, the stop method can be called to stop all its processes. However, a ProcessNetwork will self-terminate if all user (i.e. non-daemon threads) have terminated.
Note: processes within a ProcessNetwork should not make calls to their network's start, suspend, resume, join or stop methods.
import jcsp.lang.*; public class ProcessNetworkExample1 { public static void pause (int time) { try {Thread.sleep (time);} catch (InterruptedException e) {} } public static void main (String[] argv) { System.out.println ("*** start the network"); new ProcessNetwork ( new CSProcess () { public void run () { while (true) { System.out.println (":-) network running in the background"); pause (500); } } } ).start (); System.out.println ("*** I'm still executing as well"); System.out.println ("*** I'm going to take 5 ..."); pause (5000); System.out.println ("*** I'll take another 5 ..."); pause (5000); System.out.println ("*** I'll finish now ... so the network should as well."); } }
import jcsp.lang.*; public class ProcessNetworkExample2 { public static void pause (int time) { try {Thread.sleep (time);} catch (InterruptedException e) {} } public static void main (String[] argv) { ProcessNetwork network = new ProcessNetwork ( new CSProcess () { public void run () { while (true) { System.out.println (":-) network running in the background"); pause (500); } } } ); System.out.println ("*** start the network"); network.start (); for (int i = 0; i < 5; i++) { pause (5000); System.out.println ("*** suspend the network (" + i + "/" + 4 + ")"); network.suspend (); pause (5000); System.out.println ("*** resume the network (" + i + "/" + 4 + ")"); network.resume (); } pause (5000); System.out.println ("*** stop the network"); network.stop (); System.out.println ("*** and finish myself!"); } }
ProcessManager
Constructor Summary | |
ProcessNetwork(CSProcess process)
Deprecated. |
Method Summary | |
void |
join()
Deprecated. Join the network (that is wait for the the network to terminate). |
void |
resume()
Deprecated. Resume the network. |
void |
run()
Deprecated. Run the network (that is start it and wait for it to terminate). |
void |
start()
Deprecated. Start the network (but keep running ourselves). |
void |
stop()
Deprecated. Stop (permanently) the network. |
void |
suspend()
Deprecated. Suspend the network. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ProcessNetwork(CSProcess process)
process
- the CSProcess to be executed by this ProcessNetworkMethod Detail |
public void start()
public void stop()
public void suspend()
public void resume()
public void join()
public void run()
run
in interface Runnable
|
CSP for Java (JCSP) 1.0-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |