然后,6L这种调用程序的做法,跟我说的开新进程有点不一样。 比如说我在调用某个的类的一个方法的时候,在一般情况下这个方法会在当前进程里运行,但是我希望它可以运行在一个新开的进程里,方法也是一段代码,但是不是有入口的程序。
如下方法: public class Test { /** * @Description: TODO * @param @param args * @return void * @throws * @author lxj * @date 2015-5-13 */ public static void main(String[] args) { // TODO Auto-generated method stub Runtime runtime = Runtime.getRuntime(); try { Process process = runtime.exec("java Test1"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ------------------- public class Test1 { /** * @Description: TODO * @param @param args * @return void * @throws * @author lxj * @date 2015-5-13 */ public static void main(String[] args) { // TODO Auto-generated method stub try { FileOutputStream fOut = new FileOutputStream("c:\\Test1.txt"); try { fOut.close(); System.out.println("被调用成功!"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(""); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
首先:进程是一个具体的应用程序,线程是进程中的一个分支。 其次:调用具体应用程序的方法: public static void main(String[] args) { Runtime rt = Runtime.getRuntime(); Process p = null; String fileLac = ""; try { fileLac = "D:\\Program Files (x86)\\Notepad++\\notepad++.exe";//要调用的程序路径 p = rt.exec(fileLac); } catch (Exception e) { System.out.println("open failure"); } }
楼上的哥们,人家说的是进程,不是线程。看清题目再答题。
62,614
社区成员
307,327
社区内容
加载中
试试用AI创作助手写篇文章吧