CS计算机代考程序代写 Java import java.util.concurrent.*;

import java.util.concurrent.*;

class ThreadExample {

void print (char c, int count) {
for (int i=0; i {
Integer arg;
ZotCallable (Integer anArg) {
arg = anArg;
}
public Integer call () {
return zot (arg);
}
}

void sequentialExecution () {
System.out.printf (“Sequential Execution\n “);
foo();
Integer result = zot (0);
bar();
bat();
System.out.printf (“\n”);
}

void sequentialExecutionUsingRunnable () {
System.out.printf (“Sequential Exeecution Using Runnable\n “);
foo();
ZotRunnable zot = new ZotRunnable (0);
zot.run();
Integer result = zot.result;
bar();
bat();
System.out.printf (“\n”);
}

void explicitThreadManagement () {
System.out.printf (“Explicit Thread Management\n “);
foo();
ZotRunnable zot = new ZotRunnable (0);
Thread t = new Thread (zot);
t.start();
bar();
Integer result = null;
try {
t.join();
result = zot.result;
} catch (InterruptedException ie) {}
bat();
System.out.printf (“\n”);
}

void executorService () {
System.out.printf (“Executor Service\n “);
ExecutorService ex = new ScheduledThreadPoolExecutor (2);
foo();
Future resultFuture = ex.submit (new ZotCallable (0));
bar ();
Integer result = null;
try {
result = resultFuture.get ();
} catch (InterruptedException ie) {
} catch (ExecutionException ee) {}
bat();
ex.shutdown();
System.out.printf (“\n”);
}

public static void main (String[] args) {
ThreadExample te = new ThreadExample();
te.sequentialExecution();
te.sequentialExecutionUsingRunnable();
te.explicitThreadManagement();
te.executorService();
}
}