I create a class which extends Thread.

I can start the thread with run() method but the new thread does not runs parallel on my main application. I try the start() method which runs perfect and parallel to my to my main application.
-Here i could not understand what is the difference start() and run() methods clearly.

And after here i could not found how to wait and resume the thread. Java 1.7 has changed many methods. They works but they don't recommend many thinks... I need to support 1.6 and 1.7 java on my application...

I am waiting for your help...

Thank you!

5 Years
Discussion Span
Last Post by JamesCherrill

Java 1.7 hasn't broken anything from 1.6, so code for 1.6 and it will run on both.
When you create a thread you supply a run() method. Normally you call Thread's start() method which starts a new thread and calls run() on that thread. There's nothing to stop you calling run() yourself, but if you do it's just executed on your current thread, not a new one.


Why i can start properly with start() method the thread but i can not start a threa with run() ?

And if i have started the thread with start() mtehod, and after a time i call wait() method ti gives me this error:



I thought I answered that. If you call run() you're just calling your own method on your own thread. It's the start() method that actually creates a new thread, then calls your run method on that new thread. If you don't call start() you don't get a new thread.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.