File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Multiple threads not running from jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Multiple threads not running from jar file" Watch "Multiple threads not running from jar file" New topic
Author

Multiple threads not running from jar file

saurabh kapoor
Greenhorn

Joined: Nov 28, 2011
Posts: 3
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

Joined: Mar 22, 2000
Posts: 11862
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

Java Resources at www.wbrogden.com
saurabh kapoor
Greenhorn

Joined: Nov 28, 2011
Posts: 3
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

Joined: Mar 05, 2008
Posts: 2127
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

Joined: Aug 25, 2003
Posts: 202

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

Joined: Nov 28, 2011
Posts: 3
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
Bartender

Joined: Oct 14, 2005
Posts: 13842

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

Joined: Aug 25, 2003
Posts: 202

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

Joined: Oct 26, 2003
Posts: 343

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 .


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
 
 
subject: Multiple threads not running from jar file
 
Threads others viewed
Cannot register driver
Monitoring standalone java program
Game Tutorials -->> Creating An Executable JAR File
jar
could not find the main class
IntelliJ Java IDE