This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple threads not running from jar file  RSS feed

 
saurabh kapoor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a package consisting a main class which is having multiple threading concept.. Threads are part of other classes whose objects are getting instantiated in main class.. This thing is perfectly working under Net Beans 6.9.1 environment. but when i m creating a jar file n double clicking on it, threads are not running.. Can anyone please tell me the solution......
Thanks in advance
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect some classpath problem is causing your program to throw an exception before it can start the Threads.

Execute from a command prompt window instead of double-clicking so you can see the exception report.

Bill
 
saurabh kapoor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:I suspect some classpath problem is causing your program to throw an exception before it can start the Threads.

Execute from a command prompt window instead of double-clicking so you can see the exception report.

Bill


I have provided all the classpaths accurately, even of the various APIs i m using in my program. But it is stiil not working.. Not even a single thread is executing after clicking or starting from command prompt.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the program is running at all, from the executable jar? Is there any other output, for example?

You might try putting some catch statements in your code, to make sure that if any exceptions are thrown (or even Errors), you get some sort of stacktrace printed out. Put these in the main() method, and also inside the run() method for each Thread or Runnable. For example:

I know, people here will probably whine about how it's horrible to ever catch Throwable, whatever. Just try it temporarily as a test, to see if you catch anything, and then change it to Exception later (or remove the try/catch entirely) if it doesn't tell you anything useful.
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few questions:

1) How exactly are you running it from command-prompt?

2) Does you JAR file has a manifest, specifying Main-Class?

3) What kind of interface does your application have (GUI / Character-based)?

3) How are you assessing if there are any threads running or not?
 
saurabh kapoor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Jha wrote:A few questions:

1) How exactly are you running it from command-prompt?

2) Does you JAR file has a manifest, specifying Main-Class?

3) What kind of interface does your application have (GUI / Character-based)?

3) How are you assessing if there are any threads running or not?


M trying to run it by putting shortcut of jar file in start-up folder of windows. JAR has a manifest and name of main class is Main. Interface is character based. Package built is somewhat to do processes at back end. I m assessing threads by implementing "Runnable" interface with classes and creating threads in their constructors..
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saurabh kapoor wrote:
Aditya Jha wrote:
3) How are you assessing if there are any threads running or not?


I m assessing threads by implementing "Runnable" interface with classes and creating threads in their constructors..


I think the question was supposed to mean "How do you know how many threads are running, and how do you know that is the wrong number?" (or something close to that). Your reply doesn't answer that question. What makes you think there is a problem with threads?
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saurabh kapoor wrote:M trying to run it by putting shortcut of jar file in start-up folder of windows. JAR has a manifest and name of main class is Main. Interface is character based. Package built is somewhat to do processes at back end. I m assessing threads by implementing "Runnable" interface with classes and creating threads in their constructors..

Please use proper English which is easy to read and understand for everyone.

There is just so much that can go wrong here.

For starters, putting a short-cut of JAR file may or may not work depending upon whether the system is configured to use 'java -jar "%1"' command line for JAR files by default, that too assuming your JDK bin directory is in PATH environment variable.

Secondly, your application has a character-based interface. Trying to run it from a JAR file (even with java -jar) is going to result in a process that logs messages in a command (shell) environment which will close automatically on JVM exit, whether successfully or due to any error. In other words, you won't see anything at all. You may want to use a short-cut for 'cmd /K "java -jar <jar-file-name>"' instead.

As explained by Paul, it would be helpful to know how exactly are you determining that there are no threads running.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the answer your just not running the jar at all and can't see the problem ...

I suspect what your missing is your running Windows and you haven't associated the file type jar with java hence double clicking it does nothing , if it works from the command line java -jar then google file asoociations .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!