Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to learn to walk before you start trying to run.</p> <ul> <li><p>Read / do a tutorial on Java programming. This should explain (among other things) how to compile and run a Java program from the command line.</p></li> <li><p>Read / do a tutorial on JMS.</p></li> <li><p>Read the Oracle material on how to create an executable JAR file.</p></li> <li><p>Figure out what it is you are trying to do ... and <strong>design</strong> your application.</p></li> </ul> <hr> <p>Looking at what you've shown and told us:</p> <ul> <li><p>You <em>could</em> add a main method to that class, but to make an <em>executable</em> JAR file, you've got to create your JAR file with a manifest entry that specifies the name of the class with the main method.</p></li> <li><p>There's a lot more that you have to do before that code will work:</p> <ul> <li><p>add code to (at least) log the exceptions that you are catching</p></li> <li><p>add code to process the messages</p></li> <li><p>add code to initialize the connection factory and connection objects</p></li> </ul></li> <li><p>And like I said above, you probably need some kind of design ... so that you don't end up with everything in a "kitchen sink" class.</p></li> </ul> <hr> <blockquote> <p>if I add main method, should I simply call receiveMessages() in main? </p> </blockquote> <p>That is one approach. But like I said, you really need to <em>design</em> your application.</p> <blockquote> <p>And then after running, will the listener keep on running? </p> </blockquote> <p>It is not entirely clear. It should keep running as long as the <code>main</code> thread is alive, but it is not immediately obvious what happens when your <code>main</code> method returns. (It depends on whether the JMS threads are created as daemon threads, and that's not specified.)</p> <blockquote> <p>And if there are messages, will it retrieve automatically in onMessage method? </p> </blockquote> <p>It would appear that each message is retrieved (read from the socket) <em>before</em> your <code>onMessage</code> method is called.</p> <hr> <blockquote> <p>Also, if the listener is continuously listening, doesn't it take CPU???</p> </blockquote> <p>Not if it is implemented properly.</p> <blockquote> <p>In case of threads, when we create a thread &amp; put it in sleep, the CPU utilization is zero, how doe it work in case of listener?</p> </blockquote> <p>At a certain level, a listener thread will make a system call that <em>waits</em> for data to arrive on a network socket. I don't know how it is exactly implemented, but this <em>could</em> be as simple as an <code>read()</code> call on the network socket's <code>InoutStream</code>. No CPU is used by a thread while it waits in a blocking system call.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload