All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.lang.ProcessNetwork
This class can be used to suspend a process network to save processor usage when the network is not required and then resume it when it is required again (For example when an Applet is not on the screen).
When the ProcessNetwork is not required after the processing has finished the stop method can be called to stop all the CSProcess's within the ProcessNetwork.
NOTE: CSProcess's within the ProcessNetwork should not make calls to their ProcessNetworks start, stop, suspend or resume methods as they will either cease to execute or not be running anyway.
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) { new ProcessNetwork(new CSProcess() { public void run() { while (true) { System.out.println("Still running in the background"); pause(500); } } }).start(); System.out.println("I'm still executing as well"); System.out.println("Wait a while"); pause(5000); System.out.println("Woke up. Now I'm finished the ProcessNetwork should exit 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("Still running in the background"); pause(500); } } }); network.start(); pause(5000); System.out.println("Suspend the Network"); network.suspend(); pause(5000); System.out.println("Resume the Network"); network.resume(); pause(5000); System.out.println("Stop the Network"); network.stop(); pause(5000); } }
public ProcessNetwork(CSProcess process)
public void start()
public void stop()
public void suspend()
public void resume()
public void join()
public synchronized void run()
All Packages Class Hierarchy This Package Previous Next Index