/** * * 鍒濆鍖栫嚎绋嬫睜 * * @param threads */ private static void resizeWorkThreads(int threads) { // System.out.println("threads:"+threads); if (threads > 0) { for (int i = 0; i < threads; i++) { WorkThread wt = new WorkThread(); wt.setPriority(Thread.MIN_PRIORITY); wt.start(); pooledWorkThreads.addElement(wt); } } else { for (int i = 0; i < 0 - threads; i++) { int count = pooledWorkThreads.size(); if (count > 0) { WorkThread wt = (WorkThread) pooledWorkThreads.elementAt(count - 1); pooledWorkThreads.removeElementAt(count - 1); while (!wt.IsIdle()) { try { Thread.sleep(0); } catch (InterruptedException e) { // TODO Auto-generated catch block // e.printStackTrace(); } } wt.exit(); } } } }
/** 鍚戠嚎绋嬫睜娣诲姞鏍煎鐨勭嚎绋� */ private static void addThreadToPooled() { WorkThread wt = new WorkThread(); wt.setPriority(Thread.MIN_PRIORITY); wt.start(); pooledWorkThreads.addElement(wt); // System.out.println("娣诲姞绾跨▼"); }
private Object getval(PluginRPort port) { WorkThread p = new WorkThread(ab); p.start(); try { Thread.sleep(1000); } catch (InterruptedException e) { VM.println("Interrupted."); } Object o2 = p.obj; // VM.println("plupp " + o2); if (p.obj != null) { // p.stop(); } return o2; }
/** 纭繚绾跨▼姹犲凡缁忓垵濮嬪寲 */ static { if (!initialized) { pooledWorkThreads = new Vector(); quequeWorkTaskDatas = new Vector(); resizeWorkThreads(DEFAULT_MAX_WORKTHREADS); WorkTaskData data = new WorkTaskData( new WaitCallback() { public void execute(Object state) { dispatchWorkItem(); } }, null); innerThread = new WorkThread(); innerThread.setWorkTaskData(data); innerThread.start(); initialized = true; } }