Your SlideShare is downloading. ×
0
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Thread presentation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Thread presentation

195

Published on

Threads in java

Threads in java

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
195
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Multithreading in Java
  • 2. Multitasking - Multithreading Hello Class Handling multiple tasks – Multitasking Ability to initiate multiple processes - Multithreading
  • 3. Process & Threads Process Threads Spell Checker in word can be considered as a thread An application running is called a process, a process can have multiple threads.
  • 4. Example - Thread NFS ROAD RASH Games are best example for applying Multithreading
  • 5. What are Threads? • Two or more tasks executing concurrently within a single • • • • • program. It is an independent path of execution in a program. You always have thread in your application even if you don’t create it. main method is a thread and also known as main thread. Threads are scheduled by OS to be processed by the Processor, so its behavior depends on the OS. It cannot be guaranteed about threads execution. In java it is created & controlled by java.lang.Thread class
  • 6. Creating Threads Thread t = new Thread(); Thread Just creates Thread Object t.start(); public void run(){ // starting point for thread } -To start the thread start method should be invoked -No guarantee about when it will start, depends on OS scheduler
  • 7. Starting up with Threads • There are two ways to create thread in java; • By Extending the Thread class (java.lang.Thread) • instance of a class that inherits from thread • Implement the Runnable interface (java.lang.Runnable) • instance of thread where you pass the behavior of the thread into the thread constructor • Let us see examples
  • 8. Lifecycle of a Thread
  • 9. Thread - sleep() • A method used to tell the current thread to sleep for certain • • • • time. Sleep method accepts time in milliseconds. Can throw InterruptedException. Cannot guarantee that a thread goes to sleep for specified time. Once sleep state is complete, the thread can move to Runnable or Running state.
  • 10. Action Listener
  • 11. Action Listener Example • When you create a button on a Frame, and when you press it and something happens that is called ActionListener. We tell the button to do something when it is clicked. Or it can be performed on TextBox, CheckBox, Radio Buttons, etc.
  • 12. ActionListener • Action Listeners are the event handlers to be implemented, that you decide what to should be done or performed on certain user operations. The event occurs whenever an action is performed by user. • Example 1 • Example 2
  • 13. Done!

×