• Post Reply Bookmark Topic Watch Topic
  • New Topic

I'm new to java and threads needs some help please...  RSS feed

 
Joey Brown
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on this for a while now and can't seem to get the thread thing down. What I'm doing is creating an installer. I have some jar files that have to be unzipped and I'm doing this using this code.


And that works fine... But, it freezes the java program and doesn't allow me to print output to the screen so that the user knows that it is working. Well, I was told that I needed to use threads in order to make it were it didnt freeze the program window. I've been trying to get threads to work so that it will do this command and then wait until everything is extracted and the call another thread that does the samething just to a different jar file. Like, I said before I'm new to java. I've spent hours reading thru threads forums and tutorials and can't get it to work. Thanks to anyone that takes the time to help a noob.
 
Ulises Pulido
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good start is to put all that code like this:



in your class that will call this method you put.

MyOperation operation = new MyOperation();
Thread installer = new Thread(operation);
installer.start();

and there you go your installer running in another thread.

I removed your Throwable e clause because I don't like it and most of the companies you will be hired for neither, try to be more specific on the type of Exceptions that you are catching, that's another good start.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be more specific about a couple of points:

1) What do you mean by 'it freezes the java application'? How do you know the application is frozen? What does frozen mean?
2) You say 'doesn't allow me to print output to the screen'. What do you mean by print output to the screen? What screen? Are you saying those System.out.printlns never reach the console? Or is there some other output not being displayed?
3) Can you tell us more about your environment, what kind of application, what version of Java, anything else that you think might be important?

The point is this: I don't see why those System.out.printlns would not be display on the screen. So if that is not happening I don't think adding Threads will help because there is some other issues. Everything the previous poster said is pertinent, especially about the Exception handling. The best root to solve your problem, though, might not be to wrap your task in a Thread, it depends on your environment and what your real problem is, which is not yet clear (to me anyway).
 
Joey Brown
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea that's what I tried to do at first but it would run all of my commands at the same time. Yea it was freezing the window while it extracted. I have a GUI. But, I was able to get it to work with this.


So Thanks for your help.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!