Tutor HuntResources Java Resources

Java Threads

Intro to the world of threads

Date : 24/05/2017

Author Information

Bharat

Uploaded by : Bharat
Uploaded on : 24/05/2017
Subject : Java

To begin with one should get a feel of what thread is. So, what is a thread ? a methods, a class, an interface. It is none of them. Thread is something ( a facility ) that can run a method. So, if there are two threads, they each run a method at the same time. So, three threads run three methods and so on....

So, may be i can say that thread is something that runs a method or do a job. So, method feels like a job and thread feels like a person who does the job.

If you have been programming, you are already using one thread. So, when you run a java program, jvm creates a thread called main thread and asks it to run the main method. So, if you create another thread or two in main method, you have to give those new threads a method each to run.

How does thread run a method ? A thread is a facility that knows how to use cpu time (share CPU) and it also gets a memory stamp (piece of memory) of this own to use. Using the CPU and the methods, it can run a method.

So, when many threads run one method each at the same time you see many things happening at the same time. This is multi threading.

Getting a feel of thread is more important, writing the code to create a thread in your program is easy to find in any book or internet. There are two ways of creating threads in Java.

This resource was uploaded by: Bharat

Other articles by this author