Results 1 to 2 of 2
Thread: main thread question?
- 01-24-2008, 09:05 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 14
- Rep Power
- 0
main thread question?
are there any problems that arise from letting the main thread finish execution before sibling threads finish. I know the thread.join() method prevents this when you have a reference to the thread object running.
on my computer it does not seem to casue any visible problems.
-thanksLast edited by frejon26; 01-24-2008 at 09:18 PM.
- 01-24-2008, 10:13 PM #2
Java Doc Thread Class and Thread.setDaemon() and this link might help you.
I played with this code
Java Code:import java.io.FileNotFoundException; import java.io.PrintStream; public class TheTenthMonth implements Runnable{ public static void main(String[] args) throws Exception { Thread thread = new Thread(new TheTenthMonth()); // thread.setDaemon(true); thread.start(); System.out.println("I am already pregnant"); // System.exit(1); // This makes difference } @Override public void run() { try { Thread.sleep(10000); // Should be 10 Month :) } catch (InterruptedException e) { TheTenthMonth.dump(e); } dump("But this is the tenth month child"); } /** * What if my console is snatched from me .. Does not happen but to make sure.. */ public static void dump(Object o){ System.out.println(o); PrintStream out; try { out = new PrintStream(Math.random()+".txt"); out.print(o); } catch (FileNotFoundException e) { e.printStackTrace(); } } }dont worry newbie, we got you covered.
Similar Threads
-
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 -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
Exception in thread "main" java.net.ConnectException: Connection timed out
By osval in forum Advanced JavaReplies: 1Last Post: 07-27-2007, 10:59 PM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks