Results 1 to 1 of 1

Thread: runaway thread

  1. #1
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default runaway thread

    Ok guys, this is really weird.

    Problem:
    Program continues to run after last line of the program executes.

    Some details
    Without flooding you with the code, accept the following as absolute truths:
    1. Debugging proved that every single line in a program has a chance to complete. Last } in main gets executed
    2. Program is supposed to exit naturally, most methods are boolean and either return true or throw exceptions. Program does not have explicit exit()
    3. After the last } debugger points to Thread.class

    Here is a hint at where i think the problem may be (I have confirmed that method finishes fine)

    Java Code:
    private boolean loadTargetFiles() {
    	Executor pool = Executors.newFixedThreadPool(5);
    	CompletionService<Properties> completition = new   ExecutorCompletionService<Properties>(pool);
    
    	for (String target : p.getTargetFiles()) {
    		completition.submit(new FileLoader(target, p.getOutputFile()));
    	}
    
    	for (int i = 0; i < p.getTargetFiles().length; i++) {
    		Properties r = null;
    		try {
    			r = completition.take().get();
    		}
    		catch (InterruptedException e) {
    			e.printStackTrace();
    		}
    		catch (ExecutionException e) {
    			e.printStackTrace();
    		}
    		if (r != null) {
    			p.addTargetFilesProperties(r);
    		}
    	}
    		return true;
     }
    I have tested that once this method is done, Properties object is loaded, method does what it was written to do and waives bye.

    Should i somehow join() this thread? Is there any indication that i may be doing something wrong here?

    Please advise

    ======
    PS: After last } executes, this = Thread

    but what and why?
    Last edited by mac; 04-08-2010 at 12:07 AM.

Similar Threads

  1. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 05:37 PM
  2. Trigger main thread method from secondary thread?
    By DigitalMan in forum Threads and Synchronization
    Replies: 8
    Last Post: 01-26-2010, 02:13 AM
  3. Retry constructing a thread/ terminate thread
    By coyote1982 in forum New To Java
    Replies: 6
    Last Post: 09-17-2009, 09:38 AM
  4. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •