why My main thread exit when IOStreamConnectorThread exits?
mahshid shakiba <[email protected]>
| Newsgroups | gmane.comp.java.sshtools.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have started using SSHTools in my application one month ago. My
application should connect and run commands on the remote server
regularly. In my main application I have loop and in this loop I will run
the commands on the remote server. My problem is that after the first use
of openSessionChannel() , startshell() and finally exiting the usershell,
my main thread also seems to exit.
Here is an example of my code:
public class myclass()
{
static SshClient ssh=null;
static SessionChannelClient shell_session=null;
//it is a swing application
public myclass()
{
//initialize my frame and panel ...
}
public static void main(String[] args)
{
//initialize the ssh with password authentication
myclass my=new myclass();
while(true)
{
System.out.println("reached here"); //only printed once!!
I do not know why??
shell_session = ssh.openSessionChannel();
if (!shell_session.requestPseudoTerminal("vt100", 80, 24, 0,
0, ""))
{ System.out.println("Failed to allocate a pseudo terminal");
shell_session.close();
throw(new Exception());
}
if (shell_session.startShell())
{
IOStreamConnector output,error;
output = new IOStreamConnector();
error = new IOStreamConnector();
myStdOutPrintStream = new PrintStream(
new
BufferedOutputStream(
new
FileOutputStream(new File("c:\\myoutput.txt")) ));
output.connect(shell_session.getInputStream(),
myStdOutPrintStream);
error.connect(shell_session.getStderrInputStream(),
System.out);
OutputStream out = shell_session.getOutputStream();
String cmdd="runblast" + "\n";
out.write(cmdd.getBytes());
//wait untill the command is executed and read the
result from the file
cmdd ="exit\n";
out.write(cmdd.getBytes());
shell_session.getState().waitForState(ChannelState.CHANNEL_CLOSED);
output=error=null;
shell_session.close();
shell_session=null;
} //if
}//while
} //main
} //myclass
after the "INFO: IOStreamConnectorThread is exiting" in log , the
"reached here" message is not displayed anymore. It seems like as if my
main thread exited with IoStreamConnector!!
I appreciate if you can help me.
Thanks for your time and have a great day.
Mahshid
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click