advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Busy Waiting
More on the Stop() Method
Imagine waiting for your document to print before you could resume typing. Imagine waiting for a Web server to handle every request sequentially that had arrived before you did. How can your applications benefit from a multithreaded design to enhance performance and effectiveness?
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 3.7/5 | Rate this item | 3 users have rated this item.
Email this articleEmail this article
 
An Introduction to Java Thread Programming
Multi-threaded programming is all but essential for complex problem solving and effective user interfaces. Yet, to many programmers, it remains an arcane science. Java makes threaded programming simple due to its portable nature. 

advertisement
he concept of threaded programming isn't new; most modern operating systems provide support for threads in some fashion. However, as widespread as threads are, the number of developers who have worked with them is fairly small. The cause of the problem is not clear—perhaps because threaded code is virtually unportable; perhaps because threaded programming requires techniques that aren't familiar to many developers.

However, threaded programming is almost essential. Any substantial program is multithreaded. Java, by its very nature, solves portability problems, and the thread support in Java is so elegantly simple that any developer can pick up the mechanisms of thread programming with ease.

Threads, Defined
What precisely is a thread, however? A "thread" is shorthand for a "thread of control." At its simplest, this is just a section of code executed independently of other threads of control within a single program. We're all familiar with multitasking wherein an operating system can run more than one program at a time. A thread is much the same, but, conceptually, exists at a process level. That is, one process may be divided into multiple threads, executing simultaneously, all performing discrete tasks that contribute to the overall program.

The popularity of threads increased when graphical user interfaces became standard for desktop computers, as they gave the illusion of better performance. The programs didn't really run any faster, but separate threads could be used to (for example) print a file and receive new keystrokes from the user. No longer would users need to wait for a document to print before they could continue working, as these programs invoke a separate thread to perform the printing task in the background.

Another advantage of a thread is its improved handling of blocking I/O. In Java, just like most programming languages, input is read from a stream. If an attempt is made to read data when none is currently available, the program will simply wait (block) until input becomes available and the read request is fulfilled. In most cases, this behavior is undesirable. While blocked, the appearance to the user will be that the program has hung, as any actions appear to be ignored. By using multithreading, the Java program can create a separate thread to read data from the desired input stream. And if this thread blocks, all other threads remain unaffected and can still perform servicing and processing in the meantime.

There is a potential problem with thread programming that requires special handling. See the sidebar "Busy Waiting."
  Next Page: Creating a Java Thread
Page 1: IntroductionPage 3: The Start, Run, and Stop Methods
Page 2: Creating a Java Thread  
Untitled
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES