Is there anyway to create a new thread..basically create an object of a class within an existing thread and kill this existing thread so only the newly created child remains?

uth,


You can create a new thread at any time. Then if you so desire, let the 'main' thread die by letting the 'public static main' function return. If the thread you created is a 'daemon' thread the JVM will exit all together. However if the thread you created was a 'user' thread the JVM will not exit straight away, instead another thread will be automatically created called 'DestroyJavaVM' which will wait until all 'user' threads return and then kill the JVM. But why would you want to do this, one thread is as good as any other.


Kate

Hi Kate,

What I need to do is have another instance of the same class running and shut down the existing instance. Will try what you suggested today!Thanks!

uth,


You can create a new thread at any time. Then if you so desire, let the 'main' thread die by letting the 'public static main' function return. If the thread you created is a 'daemon' thread the JVM will exit all together. However if the thread you created was a 'user' thread the JVM will not exit straight away, instead another thread will be automatically created called 'DestroyJavaVM' which will wait until all 'user' threads return and then kill the JVM. But why would you want to do this, one thread is as good as any other.


Kate

hi!!
i wanna ask did u find any solution of below situation. Actually i want to do erxactly the same, kill the exixting thread before creating new thread.

Thx

Hi Kate,

What I need to do is have another instance of the same class running and shut down the existing instance. Will try what you suggested today!Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.