62,614
社区成员
发帖
与我相关
我的任务
分享
package thread1.ParaNull;
import java.util.Stack;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class GlobalControl {
public static int NumOfLp = 100;//at least three node r needed ,or there must be wrong .
public static double limit = 10000.0;
public static double simulationEndTime = 500.0;
public static long seed = 1233;
/*
* make it wellknown
*/
//public static LogicalProcess LP[] = new LogicalProcess[NumOfLp];
private static int GVT = 0;
private static final int POOL_SIZE = NumOfLp;//seems at least no less than the number of the NumOfLp
public void init() {
ExecutorService exe = null;//
// for performance ,we use the pool for execution
exe = Executors.newFixedThreadPool(POOL_SIZE);// �����̳߳�
int i = 0;
Event temp1;
// 1 creation
/* LogicalProcess tempLP=null;
for (int j = 0; j < GlobalControl.NumOfLp; j++) {
tempLP= LP.getInstance(j);
tempLP= new LogicalProcess(j, this, seed);
}*/
// 2 initialization of the logicalprocess
while (i < NumOfLp) {
// structure the influence set ,both side should know eachother!! the couples
LP.getInstance(i).setInfluenced((i +1 + NumOfLp)% NumOfLp);
LP.getInstance(i).setInfluenced((i - 1 + NumOfLp)% NumOfLp);
// set the rest to null ,by construction default
//
i++;
}
// 3 first push
for (int j = 0; j < GlobalControl.NumOfLp; j++) {
if (LP.getInstance(j).isFirstpush()) {
temp1 = LP.getInstance(j).remoteEventgeneration();
LP.getInstance(j).toScheduleEvent(temp1);
/*System.out.println("issue a event from the " + j
+ "LP to the " + temp1.to + "with timestamp"
+ temp1.timeStamp);*/
}
}
// start the thread execution
for (int j = 0; j < NumOfLp; j++) {
exe.execute(LP.getInstance(j));
System.out.println("we r creating the " + j + "LP");
}
}
public static void main(String[] args) {
GlobalControl global = new GlobalControl();
global.init();
}
package thread1.ParaNull;
import java.util.Stack;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class GlobalControl {
public static int NumOfLp = 100;
public static double limit = 10000.0;
public static double simulationEndTime = 500.0;
public static long seed = 1233;
private static int GVT = 0;
private static final int POOL_SIZE = 99;
//if POOL_SIZE is smaller than NumOfLp which is the number of thread ,it will deadloack ,why?
public void init() {
ExecutorService exe = null;
exe = Executors.newFixedThreadPool(POOL_SIZE);
int i = 0;
Event temp1;
while (i < NumOfLp) {
LP.getInstance(i).setInfluenced((i +1 + NumOfLp)% NumOfLp);
LP.getInstance(i).setInfluenced((i - 1 + NumOfLp)% NumOfLp);
i++;
}
for (int j = 0; j < GlobalControl.NumOfLp; j++) {
if (LP.getInstance(j).isFirstpush()) {
temp1 = LP.getInstance(j).remoteEventgeneration();
LP.getInstance(j).toScheduleEvent(temp1);
}
}
for (int j = 0; j < NumOfLp; j++) {
exe.execute(LP.getInstance(j));
System.out.println("we r creating the " + j + "LP");
}
}
public static void main(String[] args) {
GlobalControl global = new GlobalControl();
global.init();
}