Saturday, July 24, 2010

Again on j2me progress bar and thread model


Abstract:

This article is a "j2me progress bar and the threaded model" of a text added (later referred to as the original, not seen the proposal to look at).

Discussed the original thread model used in the inadequacies and shortcomings made for her new ways to improve it and give the improved implementation. UI part because the text has flexible scalability, without change.

Copyright Statement:

This paper also published in www.j2medev.com and my Blog (blog.csdn.net / alikeboy), if needed reproduced in three ways: 1) contact me and with my consent; 2) and www.j2medev.com have Articles in co-operation agreement 3) Rss polymerization by my Blog. Also need to full text is reproduced (including articles in the head), not out of context.

Body:

Foreground and background threads to interact with UI
Model of the original text, is a front for ProgressGaugeUI independent model with a background thread. When this design on maximum simplification of the complexity of communication, in fact, the model is a single direction (from BackgroundTask to PGUI communication). In accordance with the requirements of this model, programmers Override BackgroundTask of runTask () method, the obligation of regular training to check the operation of reception PGUI and made under such circumstances to reflect. This model fully believe that a background thread, will it respond to the user the right to cancel an order to a background thread, if the background thread does not respond to the trouble (such as access to a very expensive network connection), then the user is no use trying to cancel , the program will be a temporary deadlock, until the background thread have the time to check the front of the state. And in reality, in the end when the last query, what is the frequency of the problem. In the code snippet in excess of such code will affect the normal process of understanding.

This sequence from the following chart, you can see this particular process:



We need a way for us to force the end of the Task. This method provided by the background thread itself, named called cancel (). Of course there is no one way to force an immediate end to the thread (there was, because of security issues has been canceled). So cancel () method often by closing the resources (a connection, a stream, etc.) to force runTask abnormal interruption, runTask obligated under their agreement and immediately exit to capture these anomalies. A graph worth a thousand words, let us look at the process of this method.



Clearly, the key lies in front of the thread on the background thread for the callback, so that you can solve the problem. But the new questions, and this forced us to foreground and background threads together closely coupled in (because callback Well). Can achieve both front UI callback avoiding tight coupling with the background thread it?

Interface to reduce the coupling by Cancelable
Fortunately, I can use to interface with the door to this.

The previous model is like this:



To reduce the coupling, we build an interface

public interface Cancelable (

/ Bin / boot / dev / etc / home / lib / lost + found / media / misc / mnt / net / opt / proc / root / sbin / selinux / srv / sys / tmp / u01 / usr / var / vmware

backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar. gz xml2dict-read-only non-blocking in this way should return immediately (if necessary open a new thread)

backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar. gz xml2dict-read-only addition, to avoid repeated calls to this method

backup / bin / bin_old / conf / data / eshow / log / maint / news: 10 / news: 11 / news: 12 / news: 13 / news: 14 / news: 15 / news: 16 / news: 17 / news: 18 / news: 2 / news: 3 / news: 4 / news: 5 / news: 6 / news: 7 / news: 8 / news: 9 / seeds / svn / tasks / tmp / xml2dict-read-only /

public void cancel ();

)

Then join in ProgressObserver support this method

public interface ProgressObserver (

... ...

... ...

/ Bin / boot / dev / etc / home / lib / lost + found / media / misc / mnt / net / opt / proc / root / sbin / selinux / srv / sys / tmp / u01 / usr / var / vmware

backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar. gz xml2dict-read-only set to cancel the callback function when the object Task

backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar. gz xml2dict-read-only @ param co

backup / bin / bin_old / conf / data / eshow / log / maint / news: 10 / news: 11 / news: 12 / news: 13 / news: 14 / news: 15 / news: 16 / news: 17 / news: 18 / news: 2 / news: 3 / news: 4 / news: 5 / news: 6 / news: 7 / news: 8 / news: 9 / seeds / svn / tasks / tmp / xml2dict-read-only /

public void setCancelalbeObject (Cancelable co);

)

This allows the user presses the Cancel button, you can be on the Cancelable.cancel () callback. This flexibility greatly enhanced.



New code

The updated code is as follows, in addition to the above model to use, but also on the part of the BUG was corrected, the place will change in different colors. Detailed usage, see comments






Recommended links:



Professional CD Sound RA to CD-R Cloner



CONVERTING avi to mp4



converter mp4 to avi



Youtube FLV Backup + Converter Freeware



Explosion PDA Converter



Alive VIDEO Converter



Avc Player



Wizard Vertical Market Apps



AllRipper DVD to RMVB



China's ENVIRONMENTAL satellite data



Perpetually Cell Phone 3G2 Converter



how TO convert avi to wmv



Storage CARTOONS - Screen Savers



Adobe At The End Of Acquiring, At A Price Well



On The Implementation Of Financial Knowledge In The Use Of



No comments:

Post a Comment