Wednesday, February 18, 2015
Like the article?
Today, we are going to learn about Thread in JAVA.
simpleThread.java Class
public class simpleThread implements Runnable { /* What is Thread in JAVA Programming? Ans: Thread is a path of execution within a program. Multi Threading is multiple path of execution at the same time. Thread is a way, how your computer allows you to do multiple things at once. This is the simplest definition of thread. Now, how we will be working with Thread in practice? Step 1: Creating a thread object from thread class Step 2: Then we will start thread Step 3: Just to start, thread will look for RUN method. Step 4: While finds run method, the code into the RUN method will be executed. we will be implementing Runnable interface here. * */ public static void main(String[] args) { System.out.println("Downloading two files..:"); // we are creating a thread object below Thread t1 = new Thread() { /* After t1.start , execution comes here to look for run Then the codes in run should be executed. */ public void run() { for (int k = 0; k <= 20; k++) { System.out.println("File 1 downloaded " + k * 5 + "%"); try { // Let the thread sleep for 1200 mili seconds. sleep(1200); } catch (InterruptedException threadExep) { threadExep.printStackTrace(); } } } }; // now, this will call run method t1.start(); Thread t2 = new Thread() { public void run() { for (int k = 0; k <= 20; k++) { System.out.println("File 2 Downloaded " + k * 5 + "%"); try { sleep(1000); } catch (InterruptedException threadExep) { threadExep.printStackTrace(); } } } }; t2.start(); /* Using Runnable Interface(run method must be overridden): Step 1: We will Create an object of the class. Which is obj1 here. Step 2: Create a thread object and pass the class object through it Step 3: Start the thread, do operation. */ simpleThread obj1 = new simpleThread(); Thread t3 = new Thread(obj1); t3.start(); /* This can be written as: Thread t3 = new Thread(new simpleThread()); t3.start(); * */ } @Override public void run() { for (int p = 0; p <= 10; p++) { System.out.println("This is my T3 thread!"); } } } /* What we are doing here: Creating couple of thread T1, T2. Then both starts and prints a for loop while both sleeps for 1200 and 1000 mili seconds respectively. See the outputs! */
Output is:
Downloading two files..:
File 1 downloaded 0%
File 2 Downloaded 0%
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
This is my T3 thread!
File 2 Downloaded 5%
File 1 downloaded 5%
File 2 Downloaded 10%
File 1 downloaded 10%
File 2 Downloaded 15%
File 1 downloaded 15%
File 2 Downloaded 20%
File 1 downloaded 20%
File 2 Downloaded 25%
File 2 Downloaded 30%
File 1 downloaded 25%
File 2 Downloaded 35%
File 1 downloaded 30%
File 2 Downloaded 40%
File 1 downloaded 35%
File 2 Downloaded 45%
File 1 downloaded 40%
File 2 Downloaded 50%
File 1 downloaded 45%
File 2 Downloaded 55%
File 1 downloaded 50%
File 2 Downloaded 60%
File 2 Downloaded 65%
File 1 downloaded 55%
File 2 Downloaded 70%
File 1 downloaded 60%
File 2 Downloaded 75%
File 1 downloaded 65%
File 2 Downloaded 80%
File 1 downloaded 70%
File 2 Downloaded 85%
File 1 downloaded 75%
File 2 Downloaded 90%
File 2 Downloaded 95%
File 1 downloaded 80%
File 2 Downloaded 100%
File 1 downloaded 85%
File 1 downloaded 90%
File 1 downloaded 95%
File 1 downloaded 100%
RELATED POSTS
Subscribe to:
Post Comments (Atom)
Search
Powered by Blogger.
Contact with Rubel
Popular Articles
-
Hello mobile apps developers! if you are developing Mobile application in Phonegap platform. You might face a problem in sometime ' C...
-
Hello Google Play Android Developers! Recently, Google is forcing its developers to use Android Studio rather than using Android Developmen...
-
Hello developers! Hope you are doing well. Many people are coming to application developing, specially in the Android arena. Now, What! Th...
-
Polymorphism We are going to create four Java class in our Polymorphism class. Those are: 1. human.java class 2. women.java class...
-
Even if you are not from Computer Engineering background, still you can have Career in Mobile Application Development. Honestly speaking, b...
-
People related to programming and coding often make mistakes or misuse the words Coders and Programmers by not knowing properly. So, questi...
-
Today we are going to learn Inheritance in JAVA. I've created four java class file. Those are: 1. fatherswealth.java ( Superclass ) ...
Tags
- About Me
- admob
- advice
- Android
- Android Development
- android help
- Android SDK set Up
- Android Studio
- Apps development
- Artcell
- bluehost
- body building
- Can't you make your body building at home?
- Career
- career opportunities
- Coding
- coding problem
- computer science and engineering
- cse
- CSS
- css tricks
- Differences Between Programmers and Coders
- Do you really need to go at Gym?
- Do you really need to go to Gym for having a good shaped body?
- Education
- engineering
- Error
- experience sharing
- fitness center
- Free templates
- good life advice
- google adsense
- google adsense success
- google play
- google play account open
- gym
- hostgator
- How can I get a Google Adsense account
- How to be a freelance
- How to develop android application
- how to develop mobile application
- how to earn money online
- how to make money online
- how to monetize mobile application
- HTML
- HTML/CSS
- Java Tutorial
- Lifestyle
- Linux
- Linux Os
- making money online
- Mobile Application Development
- mosharrof rubel
- noakhali zilla school
- online earning tips
- online earning ways
- phonegap
- Phonegap problem
- Programming
- r cannot be resolved to a variable type
- rubel
- software engineering
- southeast university
- Templates
- Ubuntu
- Ubuntu Help
- web hosting buy
- web hosting reseller
- why computer science?
- wordpress theme
Techonlogy
Subscribe Here
Label
- About Me
- admob
- advice
- Android
- Android Development
- android help
- Android SDK set Up
- Android Studio
- Apps development
- Artcell
- bluehost
- body building
- Can't you make your body building at home?
- Career
- career opportunities
- Coding
- coding problem
- computer science and engineering
- cse
- CSS
- css tricks
- Differences Between Programmers and Coders
- Do you really need to go at Gym?
- Do you really need to go to Gym for having a good shaped body?
- Education
- engineering
- Error
- experience sharing
- fitness center
- Free templates
- good life advice
- google adsense
- google adsense success
- google play
- google play account open
- gym
- hostgator
- How can I get a Google Adsense account
- How to be a freelance
- How to develop android application
- how to develop mobile application
- how to earn money online
- how to make money online
- how to monetize mobile application
- HTML
- HTML/CSS
- Java Tutorial
- Lifestyle
- Linux
- Linux Os
- making money online
- Mobile Application Development
- mosharrof rubel
- noakhali zilla school
- online earning tips
- online earning ways
- phonegap
- Phonegap problem
- Programming
- r cannot be resolved to a variable type
- rubel
- software engineering
- southeast university
- Templates
- Ubuntu
- Ubuntu Help
- web hosting buy
- web hosting reseller
- why computer science?
- wordpress theme
Sponsor
Categories
- About Me
- admob
- advice
- Android
- Android Development
- android help
- Android SDK set Up
- Android Studio
- Apps development
- Artcell
- bluehost
- body building
- Can't you make your body building at home?
- Career
- career opportunities
- Coding
- coding problem
- computer science and engineering
- cse
- CSS
- css tricks
- Differences Between Programmers and Coders
- Do you really need to go at Gym?
- Do you really need to go to Gym for having a good shaped body?
- Education
- engineering
- Error
- experience sharing
- fitness center
- Free templates
- good life advice
- google adsense
- google adsense success
- google play
- google play account open
- gym
- hostgator
- How can I get a Google Adsense account
- How to be a freelance
- How to develop android application
- how to develop mobile application
- how to earn money online
- how to make money online
- how to monetize mobile application
- HTML
- HTML/CSS
- Java Tutorial
- Lifestyle
- Linux
- Linux Os
- making money online
- Mobile Application Development
- mosharrof rubel
- noakhali zilla school
- online earning tips
- online earning ways
- phonegap
- Phonegap problem
- Programming
- r cannot be resolved to a variable type
- rubel
- software engineering
- southeast university
- Templates
- Ubuntu
- Ubuntu Help
- web hosting buy
- web hosting reseller
- why computer science?
- wordpress theme
About
Social Share
Recent
Business
Video
Gallery
videos
Popular Posts
-
Hello mobile apps developers! if you are developing Mobile application in Phonegap platform. You might face a problem in sometime ' C...
-
Hello Google Play Android Developers! Recently, Google is forcing its developers to use Android Studio rather than using Android Developmen...
-
Even if you are not from Computer Engineering background, still you can have Career in Mobile Application Development. Honestly speaking, b...
-
You could find this topic little bit interesting and may not be hoping from me! Well, I was at gym for almost one year and I think I'm ...
-
Today, we are going to learn about Thread in JAVA. simpleThread.java Class public class simpleThread implements Runnable { /* ...
-
Polymorphism We are going to create four Java class in our Polymorphism class. Those are: 1. human.java class 2. women.java class...
-
Array: An array is something more or less like a container of data. Array container contains same type of data. Read More from Orac...
-
People related to programming and coding often make mistakes or misuse the words Coders and Programmers by not knowing properly. So, questi...
-
Today we are going to learn Inheritance in JAVA. I've created four java class file. Those are: 1. fatherswealth.java ( Superclass ) ...
-
Hello developers! Hope you are doing well. Many people are coming to application developing, specially in the Android arena. Now, What! Th...
Brother, your site is very useful for us. I saved on my laptop for your site. I see every day. I have links to a site that is any help to you gently.
ReplyDeletehttp://bit.ly/1SnNeZY
Chiefs vs Falcons
ReplyDeleteChiefs vs Falcons live
nfl game pass
nfl live
live nfl
live nfl on cbs
Lions vs Saints
Lions vs Saints live
nfl game pass
nfl live
live nfl
live nfl on cbs
Rams vs Patriots
Rams vs Patriots live
nfl game pass
nfl live
live nfl
live nfl on cbs
Broncos vs jaguars
Broncos vs jaguars live
nfl game pass
nfl live
live nfl
live nfl on cbs
Texans vs Packers
Texans vs Packers live
nfl game pass
nfl live
live nfl
live nfl on cbs
Eagles vs Bengals
ReplyDeleteEagles vs Bengals live
nfl game pass
nfl live
live nfl
live nfl on cbs
Dolphins vs Ravens
Dolphins vs Ravens live
nfl game pass
nfl live
live nfl
live nfl on cbs
Bills vs Raiders
Bills vs Raiders live
nfl game pass
nfl live
live nfl
live nfl on cbs
49ers vs Bears
49ers vs Bears live
nfl game pass
nfl live
live nfl
live nfl on cbs
Giants vs Steelers
Giants vs Steelers live
nfl game pass
nfl live
live nfl
live nfl on cbs
Redskins VS Cardinals
ReplyDeleteRedskins VS Cardinals live
nfl game pass
nfl live
live nfl
live nfl on cbs
Buccaneers vs Chargers
Buccaneers vs Chargers live
nfl game pass
nfl live
live nfl
live nfl on cbs
Panthers vs Seahawks
Panthers vs Seahawks live
nfl game pass
nfl live
live nfl
live nfl on cbs
A C hello world program executable will actually have compiled code of printf() function attached to it. That is not the case with System / PrintStream class in Java. Your program calls the method of the class provided by JVM. Your program just has the call, no callee is attached to your executable (class/jar) for System.out.println() method.
ReplyDeletejava training in chennai
ya you have clearly explained the concept, so please let you share some information too.
ReplyDeleteWeb Design Company in Chennai
Just wanted to say thank you for the post. We are a small team and fairly new at this area so can use all the help we can get setting up best practices.
ReplyDeleteSelenium Training in Chennai
Very nice. Thanks for posting, Icons are the must imported graphic in design world. i find some free icon here.
ReplyDeleteNew Zealand education Consultants in Chennai
i have clear about coding samples which helps to know more new ideas to improve the business engagements easily.
ReplyDeleteDigital Marketing Company in Chennai
Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
ReplyDeleteSkilled Manpower Services in Chennai
I want talk to you sir.plz give your contact number
ReplyDeletevery very amazing explaintion....many things gather about muti thereding and important of therding...yes realy i enjoy it
ReplyDeleteDigital Marketing company in Chennai
Really Good blog post about java threads.provided a helpful information.I hope that you will post more updates like this.
ReplyDeleteInformatica Training in Chennai
this is very nice post thanks for updating your information to us.it is such a wonderful information about the software development and java is one of growing technology this is useful for me thank you so much.
ReplyDeleteHadoop Training in Chennai
01920147730
ReplyDelete