Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Threads and networking in J2ME

John Muchow (john@corej2me.com), Freelance Technical Writer
John Muchow is a freelance technical writer and the author of Core J2ME Technology and MIDP (Prentice Hall, Dec. 2001), a best-selling J2ME book that has been translated into Chinese, Korean, and Italian. Visit Core J2ME for additional source code, articles, and developer resources. You can e-mail John at john@corej2me.com for information about technical writing projects.

Summary:  Learn how to use threads in MIDlets to communicate over a network connection. Without multithreading, a MIDlet that requests a network connection blocks while waiting for a response from the network. In the real world, a user expects the application to continue running, even while a network connection is underway.

Date:  16 Mar 2004
Level:  Intermediate PDF:  A4 and Letter (719 KB | 43 pages)Get Adobe® Reader®

Activity:  7033 views
Comments:  

Summary

This tutorial has given you a broad coverage of working with MIDlets that communicate over a network connection. The intention was to focus on the importance of using threads and writing code to demonstrate how to do so.

You started the tutorial by writing a non-threaded MIDlet that would retrieve quotes from a remote server. The reason for developing this application was to show the problems associated with network access from a MIDlet that did not use a separate thread for communication. I demonstrated how the user interface blocked while waiting for a network connection to complete.

In the second section of this tutorial, I introduced threading. This included a discussion of the two threading techniques available in the Java language: creating a class that subclasses Thread, and implementing the Runnable interface. In this section, you also studied how J2ME threads differ from those available within J2SE.

The final section was dedicated to creating a multithreaded MIDlet. As in the previous section, I began with a series of screenshots to demonstrate the MIDlet you were about to write. This included showing how the multithreaded MIDlet could download more than one image at a time. I wrote the code to make it happen, and concluded with a comprehensive discussion of each aspect of the program.

Hopefully, you now have a good appreciation of why writing multithreaded applications is so important. You also have a starting point for building more comprehensive MIDlets that can use threading to increase the useability of your applications.

5 of 7 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=137146
TutorialTitle=Threads and networking in J2ME
publish-date=03162004
author1-email=john@corej2me.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).