Results 1 to 8 of 8
- 08-26-2008, 02:23 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 9
- Rep Power
- 0
passing a value from parent thread to child thread
Hi All,
I am calling a java program from a unix script .
My oblectives are
1)to pass value from scripts to main java class
2)main class should create a child thread and pass data to child and should return control back to script
3)child thread should run independtly of parent
The calling unix script is part of process and hence should return control back to its calling script immediately.
Findings
1)Without passing data thru setter getter /constructor method to child thread my objectives are met
2)When I pass the data from parent thread to child thread calling unix scripts wait till child thread finishesh its working
call.scr
java Main <list of Arguments>
Main.java
Child.javaJava Code:public class Main { public static void main(String args[]) throws Exception { String data2="Z"; String data1=null; for(int i=0;i<args.length;i++) { data2=data2+","+args[i]; } data1=data2; Child cu=new Child(); cu.setData(data1); data2=null; data1=null; cu.start(); } }
Java Code:class Child extends Thread { public String data; void setData(String data) { this.data=data; } public void run() { ----------> processing on data } }
I think due to passing of data from parent thread to child thread (Inter thread data communication/Inter process communication)
the threads are not working as desired.
Plz anybody can suggest something.....
Thanx.
- 08-26-2008, 02:44 PM #2
To debug your problem you need to add some println() statements to see where the threads are going and what the values are. When you see what is happening, that should help you to change the code so you get the desired results.the threads are not working as desired.
- 08-26-2008, 02:52 PM #3
Member
- Join Date
- Aug 2008
- Posts
- 9
- Rep Power
- 0
Hi Norm,
this is filtered code i have posted,
but when i hv actually deguued it the threads r getting generated succesfully n getting killed in manner of their life cycle.
But the cotrol is not getting back to script till child get killed .
Plz help
- 08-26-2008, 03:49 PM #4
The jvm will keep control until all the non-daemon threads have ended.cotrol is not getting back to script till child get killed .
Are you asking how to start a java program from a script and then have the java program return control to the script and still be running? Sounds like an OS interface problem. Can your script start the java program as another process (or whatever) and continue on, leaving the java program running?
Perhaps you could change your design to put all the logic in the java program so there isn't a script/java interface problem.
- 08-27-2008, 07:43 AM #5
Member
- Join Date
- Aug 2008
- Posts
- 9
- Rep Power
- 0
Hi Norm,
the unwanted results are just because off passing data from parent to child. All other things are working fine.
I am able to call the java prog from the script .But as i desired after parent passes d data and child get Started,control immediately shuld get back to script ,but in case of ppasing data its nt happening
But when I donot pass d data but for testing use hardcoded data in child then all things are getting done as i desired.
Thanx
- 08-27-2008, 08:38 AM #6
Member
- Join Date
- Aug 2008
- Posts
- 9
- Rep Power
- 0
- 08-27-2008, 02:34 PM #7
I beleive that is true.whole jvm will be a process
- 09-07-2008, 09:06 PM #8
process boundaries
In general, should be true. Subject to testing, variables do not cross compilation unit boundaires. To say that something is file scope is to say that you can see it in an editor window, without tabbing to another editor window: That is the definition of a compilation unit.
The JVM is actually the process, as the system sees it. public static void main is a thread within the JVM, which may launch a few threads of it's own - eg console and screen and maybe a monitor to wait on your main. An interesting safety issue is raised here: new Thread().setDaemon; in main and starting it when the jvm was started from a script, is likely to introduce interesting study cases ~ cases that should be studied in rareified stratospherics of thesis subjects and not be done on commercial work.
The jvm likely runs in the process space of the script, carefull attention to code correctness would reveal any intra-thread risks that are not subject to Security Manager issues.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
Thread
By sims in forum New To JavaReplies: 4Last Post: 08-25-2008, 01:59 PM -
data from the main/GUI thread to another runnin thread...
By cornercuttin in forum Threads and SynchronizationReplies: 2Last Post: 04-23-2008, 10:30 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM -
using Thread
By one198 in forum New To JavaReplies: 1Last Post: 11-21-2007, 08:01 AM


LinkBack URL
About LinkBacks


Bookmarks