Scope of Threads

Does anyone know. I want to have users be able to enter commands into a text field, and then have the text field action listener create a new thread to handle the command (because some commands are really long). My question is, after I start the newly created thread, and then return from the actionPerformed method, the newly created thread will no longer have any references pointing to it because it will have gone out of scope, so does that mean that the thread might be garbage collected while it is still running? Here is how My action listener works. Thank you.

inputField.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

JTextField field = (JTextField)e.getSource();//safe cast

String command = field.getText();

field.setText("");

UserCommandThread userCommandThread =new UserCommandThread(infoSocket, command, console);

userCommandThread.start();

}

});

[1258 byte] By [AsSiDuL0Usa] at [2007-11-27 8:04:14]
# 1
The VM retains references to all running threads. Your Thread won't be GCed midstream.
jverda at 2007-7-12 19:46:35 > top of Java-index,Core,Core APIs...
# 2
Note, however, that this is an issue of lifetime, not scope.
jverda at 2007-7-12 19:46:35 > top of Java-index,Core,Core APIs...
# 3
Actually, when a Thread is started, the instance is registered to "ThreadGroup". ThreadGroup holds this reference until the thread exits, i.e. until the run() method exits.
cprashantreddya at 2007-7-12 19:46:35 > top of Java-index,Core,Core APIs...
# 4
cool thanks. Good to know the Thread will complete before it is trashed.
AsSiDuL0Usa at 2007-7-12 19:46:35 > top of Java-index,Core,Core APIs...
# 5
wouldn't be much use if it wasn't so, would it?
ejpa at 2007-7-12 19:46:35 > top of Java-index,Core,Core APIs...