[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Condor-users] multi-threaded java application



You probably need to call setDaemon(false) on your sub-threads for them to remain living after the main thread stops. Also the join() call mentioned before in this thread could do the trick.

See the Java API docs for the Thread class:
...
When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.

public final void setDaemon(boolean on)
    Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.
    This method must be called before the thread is started.

Cheers,
Christoph

Shrader, Joshua H. wrote:
I'm fairly new to Condor, so I apologize if this is a question that has
been answered before, but I have been unable to find any information on
it.
Here's our setup: We're running condor on a grid. We have a bunch of
blades - each blade has 2 processors and each processor has 4 cores.
Each core is set up as a compute node. We submit a java job running multiple threads. It seems like once the
main thread finishes, the job returns, without waiting for any other
threads to finish.  the following java code yields the following output:
package threadtester;

public class Main implements Runnable {
private int threadNum; private Main(int i) {
        threadNum = i;
    }

    public static void main(String[] args) {
        if(args.length != 1){
            System.out.println("The command line arguments should
contain a single number, the number of threads to run.");
        }
        int numThreads = Integer.parseInt(args[0]);
        for(int i = 0; i < numThreads; i++){
            Thread t = new Thread(new Main(i));
            t.start();
        }
    }
public void run() {
        for(int i = 0; i < 10; i++){
            try {
                System.out.println("Thread " + threadNum + ": " + i);
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                System.out.println("Thread interrupted.");
                System.exit(1);
            }
        }
    }
}
The output (when run with an argument of 5 and run on the grid), is simply Thread 0: 0
Thread 1: 0
Thread 2: 0
Thread 3: 0
Thread 4: 0 Thread 5: 0 When this same program is run on a workstation (no condor), we get the
expected result of
Thread 0: 0
Thread 1: 0
Thread 2: 0
Thread 3: 0
Thread 4: 0 Thread 5: 0
Thread 0: 1
Thread 1: 1
Thread 2: 1
Thread 3: 1
Thread 4: 1 Thread 5: 1
... 10 times.
If a barrier is put into place, which stalls the main thread until all
of the other threads finish, it works fine.  Has anyone encountered this
before?  Any help is greatly appreciated.
Thanks, Josh



------------------------------------------------------------------------

_______________________________________________
Condor-users mailing list
To unsubscribe, send a message to condor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/condor-users

The archives can be found at: https://lists.cs.wisc.edu/archive/condor-users/