I am executing following ActiveMq program, to put the files in queues.
public static void main(String[] args) throws JMSException, IOException {
FileInputStream in;
//Write the file from some location that is to be uploaded on ActiveMQ server
in = new FileInputStream("d:\\test-transfer-doc-1.docx");
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"tcp://localhost:61616?jms.blobTransferPolicy.defaultUploadUrl=http://admin:admin@localhost:8161/fileserver/");
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory
.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination = session.createQueue("stream.file");
OutputStream out = connection.createOutputStream(destination);
// now write the file on to ActiveMQ
byte[] buffer = new byte[1024];
for (int bytesRead=0;bytesRead!=-1;) {
bytesRead = in.read(buffer);
System.out.println("bytes read="+bytesRead);
if (bytesRead == -1) {
out.close();
System.out.println("Now existiong from prog");
//System.exit(0);
break;
}
else{
System.out.println("sender\r\n");
out.write(buffer, 0, bytesRead);
}
}
System.out.println("After for loop");
}
When the bytesRead == -1, I want to unload the program from JVM as its task is completed. For this purpose, I had initially, used break
keyword, and its producing following output on Eclipse Console
using this, the program doesn't get unload form JVM, as the console RED button is still active.
Now I used, System.exit(0) for this purpose, and its exiting the program from the JVM. But I don't want to use System.exit(0) for this purpose. I tried to use simple void return
too in place of break
but its also not working.
Please tell why break
and return
aren't working in this case to end the program and why its still running?
Regards,
Arun