Java calls multiple classes, and java uses multiple processes to call a certain class (a class file)

java enables multiple processes to call a class (class file) import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.lang.management. ManagementFactory; import java.lang.management.RuntimeMXBean; public class MultipleProcessorAccess { private static int processorCount = 5;//5 public static void main(String[] args) { for (int i = 0; i <processorCount; i++) { p> ProcessBuilder pb = new ProcessBuilder(“java”, “PnSnapshotPerformanceTest”);//d20130306.UseJConsole pb.directory(new File(” C:/Users/yfan/Desktop/multipleTest”)); BufferedInputStream in = null; BufferedReader br = null; try { Process p = pb.start(); //returnCurrentProcessId(); // if wait the stream from server , // when one processor end can start next processor, // not multiple processor /*in = new BufferedInputStream(p. getInputStream()); br = new BufferedReader(new InputStreamReader(in)); String s; while ((s = 61; br.readLine()) !&# 61; null) { System.out.println(s); }*/ } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) {} } if (in != null) { try { in.close(); } catch (IOException e) {} } } } } private static int returnCurrentProcessId() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); int pid = Integer.parseInt(name. substring(0, name.indexOf(“@”))); System.out.println(“current process id: ” + pid); return pid; } }

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索