We know that in the operating system-level software running on the general process for the units are in each process is running at the same time to allow the implementation of a number of different concurrent threads, which allows a program to perform different operations at the same time. The use of multi-threading is designed to maximize the use of the computer CPU resources. JAVA byte-code program is the ultimate virtual machine JVM running under the same virtual machine in the process of operation are different to the adoption of multi-threaded operation. In the JAVA virtual machine, the threads used are single-threaded and multi-threaded, single-threaded implementation of the process of talking about the procedure is an effective sequence of operations, different operation of the order in which they have clear; and at the same time multi-threaded to allow the operation of different These different operations carried out at the same time complicated by the CPU clock frequency according to different ways of scheduling the implementation of scheduling them.
In the JAVA language provides a rich interface to manipulate multi-threaded, providing a variety of different methods of thread to achieve for our choice, very powerful. Cell phone software in the design, the need to implement the same network connection (Internet-based high-level HTTP communication protocol), UI awaiting scheduling, UI illusion show, games, control the operation of the data by the background or computing operations, such as continuously updated UI. Therefore, in J2ME in, KVM virtual machine also provides a powerful multi-threaded API, so that we can achieve in J2ME concurrent computing threads.
In J2ME, the main achievement of the following three methods of multi-threading.
First, the succession of Thread Class (java.lang.Thread)
Through the preparation of thread Thread-type category of succession and to rewrite the Thread class run () method thread, when the thread object will automatically be run when the run method of the implementation of the contents of the entity, thus to open up a separate thread and run up .
Such as: public class ThreadSimple extends Thread (
public ThreadSimple ()
(
/ / constructor
)
public void run ()
(
/ / run code entity
)
)
Examples of the use of thread, a direct creation of object and call start () method to run thread.
new ThreadSimple (). start (); when the start method of the implementation time will be run automatically, but when the only way to start the implementation of one thing, that will be threaded into an executable state, and then wait for the operating system for scheduling and running and therefore can not ensure the thread can start immediately. In JAVA in, Thread class implements the Runnable interface, so run through the realization of the abstract interface Runnable method.
Second, direct the realization of multi-threaded Runnable interface (java.lang.Runnable)
Runnable interface thread, only an abstract way to run, through the realization of the method of interface Runnable class to create a thread how features of the object, the object to start the thread does not need to use as a parameter and the Thread structure constructor to create objects and call the start method to start the thread.
Such as: public class RunnablSimple implements Runnable (
public RunnableSimple ()
(
/ / constructor
)
public void run () (
/ / run code entity
)
)
To achieve the target of the type of use:
RunnableSimple rs = new RunnableSimple ();
new Thread (rs). start ();
It can be seen that these two kinds of methods are adopted to start the Thread of the start of the thread, in fact, to operate all of the threads are packaged in the class Thread, the Thread object to call from the interface to control a variety of threads.
J2ME in the thread in the main method: void setPriority (int newPriority), set the thread priority, in the operating system thread scheduling is not deterministic, the method can set the priority level of the corresponding thread.
static void sleep (long millis), threads in a static method used to allow threads to enter the dormant state, the implementation of the method will allow the thread in the specified period of time dormant millis milliseconds.
void start (), so that the state is now entering the executable.
void run (), the implementation of the main thread.
void join (), wait for the termination of the thread.
boolean isAlive (), used to determine whether the thread state for Alive.
static void yield (), as far as possible to allow other threads to run.
Third, the use of combinations to achieve multi-threaded task
In J2ME, the same task has to deal with JAVA combination of categories, they are Timer and TimerTask, you can use them to achieve multi-threaded, that is from time to time to achieve a simple task.
Timer is a timer JAVA, can be achieved at a certain time to do something in a certain time period or to do certain things, namely through the method of schedule (TimerTask tt, long millis) and schedule (TimerTask tt, long start, long off).
Category is a TimerTask task, through the succession of such methods and covers the creation of a task can run.
Such as: public class TimerTaskS extends TimerTask (
public TimerTaskS () (
/ / constructor
)
public void run () (
/ / run code entity
)
)
Task call:
Timer timer = new Timer ();
/ / 3 seconds after the implementation of tasks
timer.schedule (new TimerTaskS (), 3000);
/ / 3 seconds after the implementation of the task and once every 5 seconds
timer.schedule (new TimerTaskS (), 3000,5000);
This task can be seen in the use of time can achieve the effect of thread, respectively, concurrent implementation of various operations, through the operation of Timer object type TimerTask objects, methods to schedule a time through the implementation of tasks, tasks at the end of time, usually using the cancel () to achieve.
Under normal circumstances, we in the J2ME mobile phone software to trigger a series of button operation, the procedure to respond to the treatment process will be more involved in network operations, data storage, such as the relative consumption of time and resources to operate, and these operations often require a certain The time to complete, so in dealing with key response process we often need to create threads to avoid the phenomenon of death programs.
public void commandAction (Command c, Displayable s) (
If (c == do1Com) (
/ / Create an interface thread
New Thread (new RunnableSimple ()). Start ();
)
Else if (c == do2Com) (
/ / Create a succession of thread Thread
new ThreadSimple (). start ();
)
else (
/ / Create a task thread
new Timer (). schedule (new TimerTaskS (), 3000,20);
)
)




10 users commented in " J2ME in summing up the achievement of multi-threading technology "
Follow-up comment rss or Leave a TrackbackI discovered your homepage by coincidence.
Very interesting posts and well written.
I will put your site on my blogroll.
Thank you! I am glad to hear that. Please tell me your blogroll, I will add it to my homepage.
Hello fellow members, I wanted to introduce myself. I’m Andre.
This is a great board I have checked in from time to time and I think I’m ready to participate and contribute with you guys.
I thought about starting my own board but I’m glad I found this one instead. Great Info!
See ya..
There is great business project.
As a result of long time research and development,
Planet Resource Recovery, Inc.
announces a remarkable ‘disruptive nanotechnology’
registered
under the trade name PetroLuxus.
Very special
Green technology is biodegradable,
non-hazardous and its molecules are so microscopic that it can penetrate virtually any natural or manmade material, and break the bond between those materials and hydrocarbons. PetroLuxus is being utilized to increase production 100 to 500% in marginal oil wells, and is also a silver bullet for property owners, as well as state and federal environmental agencies in the remediation of contaminated soil and water, making it possible for the first time to recover hydrocarbons and precious metals from soil that would otherwise be hauled away and burned to ash.
In case of any questions, see http://www.planetresource.net
Einfach Online oder per Post Arzneimittel bestellen.
Europas und deutsche Apotheken online.
Viagra Soft Tabs
Questions and answers about Wholesale cell phone and Bjs wholesale club. http://suglobo.com/
Hello, I want to say hi everyone.
test
Hey guys,
I just joined this forum and wanted to introduce myself. I look forward to learning and contributing.
Cheers
Hi all,
New to the forum, just thought I’d introduce myself
Hi nto All
My computer worked slowly, too much mistakes and buggs. Help me, please to fix errors on my computer.
My operation system is Win Vista.
With best regards,
FremnDymn
Leave A Reply