Wednesday 15 April 2015

java - How to open thread using process? -



java - How to open thread using process? -

i have thread write in file using printwriter

class nthread implements runnable { thread t; printwriter w; private volatile boolean running=true; public nthread(int p, printwriter w) { t=new thread(this); this.w=w; t.setpriority(p); } public void run() { while(running) { w.println("id: " + t.getid()); } } public void stop() { running=false; } public void start() { t.start(); } }

and seek using new process open thread.

public class filewrite { public static void main(string[] args) { thread.currentthread().setpriority(thread.max_priority); thread ref_mainthread=thread.currentthread(); seek { printwriter printwriter = new printwriter("c:\\write.txt"); printwriter.println("id main thread" + ref_mainthread); nthread p1=new nthread(thread.norm_priority + 4,printwriter); process process1 = new processbuilder("p1",".start()").start(); seek { thread.sleep(1000); } process1.destroy(); printwriter.close(); } grab (ioexception e) { system.out.println(e.getmessage()); } }

i seek write in 1 file 2 processes. how can it?

process process1 = new processbuilder("p1",".start()").start();

you telling operating scheme run programme named "p1", ".start()" first command line argument.

if you're on linux, it's same if typed "p1 .start" in shell window. if you're on windows, same if typed in cmd.exe window. either way, it's not going think it's going do.

the p1 in nthread p1=new nthread(thread.norm_priority + 4,printwriter); variable in java program. fact refers object can used start thread not cause programme named p1 magically appear on $path (or %path% if you're on windows.)

java multithreading process

No comments:

Post a Comment