Computing Magazine

Create New Thread Using Runnable Example

Posted on the 30 April 2012 by In7rud3r
<a href="">affiliate marketing</a>

Create New Thread Using Runnable Example
This Java example shows how to create a new thread by implementing
Java Runnable interface.

* To create a thread using Runnable, a class must implement
* Java Runnable interface.
public class CreateThreadRunnableExample implements Runnable{

* A class must implement run method to implement Runnable
* interface. Signature of the run method is,
* public void run()
* Code written inside run method will constite a new thread.
* New thread will end when run method returns.
public void run(){

for(int i=0; i < 5; i++){
System.out.println(“Child Thread : ” + i);

catch(InterruptedException ie){
System.out.println(“Child thread interrupted! ” + ie);

System.out.println(“Child thread finished!”);

public static void main(String[] args) {

* To create new thread, use
* Thread(Runnable thread, String threadName)
* constructor.

Thread t = new Thread(new CreateThreadRunnableExample(), “My Thread”);

* To start a particular thread, use
* void start() method of Thread class.
* Please note that, after creation of a thread it will not start
* running until we call start method.

for(int i=0; i < 5; i++){

System.out.println(“Main thread : ” + i);

catch(InterruptedException ie){
System.out.println(“Child thread interrupted! ” + ie);
System.out.println(“Main thread finished!”);

Typical output of this thread example would be

Main thread : 0
Child Thread : 0
Child Thread : 1
Main thread : 1
Main thread : 2
Child Thread : 2
Child Thread : 3
Main thread : 3
Main thread : 4
Child Thread : 4
Child thread finished!
Main thread finished!


<a href="">affiliate marketing</a>

You Might Also Like :

Back to Featured Articles on Logo Paperblog

These articles might interest you :

  • Dying Games – Steve Robinson

    Dying Games Steve Robinson

    Crime Fiction5*s The genealogical expert Jefferson Tayte is back! I love this series which has taken me back to historical eras I know little about while tellin... Read more

    10 hours, 19 minutes ago by   Cleopatralovesbooks
  • Crushed a Flower with a Footstep

    (Photograph by Abhay Tiwari) Please, talk to me about who you were before the walls were painted blue; Tell me the bruises, the aches, and time just added... Read more

    11 hours, 27 minutes ago by   Shantam Sahai
  • Make My Day . . .


    Read more

    11 hours, 42 minutes ago by   Vickilane
  • Lifestyle: Productive Procrastination

    Lifestyle: Productive Procrastination

    I’ve moaned about it enough, so you’ll all know by know that despite having graduated last summer I’m still studying. I’ve chosen a career path which pretty muc... Read more

    12 hours, 42 minutes ago by   Ninegrandstudent
  • Why I’m Not At the MidAmerica Region Annual Assembly

    I love Chicago. I have family there that I'm normally always looking for a way to be with. And I have friends that I don't see nearly enough. So when I first... Read more

    13 hours, 57 minutes ago by   Eastofmidnight
  • Lemon Stuffed French Toast

    Lemon Stuffed French Toast

    Whenever I have stale bread I want to make one of two things . . . either I want to make a bread pudding, or I want to make French Toast. Today the French... Read more

    14 hours, 42 minutes ago by   Mariealicerayner
  • Safety First And Workout Related Injuries Last

    Safety First Workout Related Injuries Last

    (Image Credit) Like most things in life, exercise can be a dangerous game. It’s very easy to injure yourself while you’re exercising; if you fail to take the... Read more

    18 hours, 39 minutes ago by   Peppertan


By renevo4
posted on 01 June at 08:12
Report spam/abuse

After my new engagement

By belstaff uk
posted on 19 January at 02:32
Report spam/abuse

belstaff coats sherlock izle mobi

By inonenddiuchE
posted on 17 January at 03:52
Report spam/abuse

Hi guys

Wondered if anyone can offer some advice on this please....

About a week ago I sold my old car via ebay. The winning bidder got in touch and wanted to collect the car on the following day. He was flying from Jersey and could only do this day. A 'friend' of mine (lets call him Dave) offered to see him on my behalf as I had work commitments and do the handover. The car was L850 and I said he could have L50 for his efforts - literally the bloke was just picking the car up and was there all of about 10-15 minutes.

Anyway, the handover all went fine and that evening I got a call from Dave saying that it all went smoothly. I agreed to meet him the next day as it was getting late to collect the cash. Anyway, the next day I get a text saying he was busy until 5pm and said to come round then. At 4:30 I get another text saying he has to go to the local hospital as his leg had swollen up - he had a trapped nerve in his leg the week before, so I didnt see anything unusual. I offered to give him a lift but he said his other friend was.

He then disappeared for 3 days and I could not reach him on the phone at all. I also tried calling at his flat. I then decided to ring the hospital admission board who confirmed that he was NOT admitted to any of the local hospitals. I then text him again and asked sternly what was happening and got a text back saying 'im in hospital - will try to call you later'. I didnt hear from him for a further 2 days and after several texts, calls and visits to his flat sent him a text asking what was going on as I had called the hospital and he wasnt admitted. Also, upon the numerous visits to his flat there were signs of activity - tv on sometimes, rubbish outside etc. and although he often had friends there, it was obvious he was around.

I then visited yesterday and waited and waited, rang his door bell, continued to keep ringing his phone etc. and then I got the following message - 'thanks for your message of distrust. Given that youve think the worst of me, I will show you my worst. Dont call round my flat again and if you want your money back you can take me to court...'

From my point of view, he went off the map for a week with my cash and lied that he was in hospital when he wasnt. I am sure he has spent all or part of the cash. I messaged him back putting everything across my my perspective and received nothing back.

Hes always been a pretty decent friend however hes got a bit of a side to him and knows some nasty and dangerous people. As much as I want my money back and have a confession via facebook that he has stolen my cash, Im a bit worried about reporting it to the police etc. as he may well do something beyond the law. On the flip side, hes effectively stolen my car!

Any advice appreciated