Asynchronous Programming

In my early Java2Script development days, I think a lot about asynchronous programming. AJAX was hot and is still hot. What is most important factor in AJAX technologies? I think it is “Asynchronous”. Without asynchronous programming, visitors still need to waste their time waiting for browser to fetch the next page. What a bad user experience.

In fact, asynchronous programming is not an easy work. Lots of callbacks, lots of threads, lots of locks or semaphores. All these stuffs may be messed up into an unmaintainable geeky thing.

Actually, if there are tools helping to design and maintain such codes, it is not a big job. If you use Java, you won’t get stuck at those threads of synchronized locks, as lots of debug tools help you figure out how those things work together at any moment you want to take a look. In fact, there are lots asynchronous programmings in Java design patterns or codes. But in Java world, asynchronous programming is not an outstanding features, and it is seldom discussed as an important issue.

But in JavaScript world, in browser world, asynchronous programming is a huge thing. In JavaScript (also known as EMCAScript)? language specification, there are no threads, no semaphores, no locks. All things are designed in synchronized mode. And before AJAX was hot, there are no robust tools for developers to write and debug JavaScript. If JavaScript sources file size exceeds 100K, it would be a hard-ass job to maintain. And if there are 3 layers of callbacks, it would drive developers crazy to develop new features. From my early experience, I designed a web form with digital signature functions, I used Java Applet in the back-end and used AJAX-style dialogs. And in oder to make a correct call from dialogs to Java Applet, its parameters may be passed through about 4-6 callback layers, because there are security issues over JavaScript calling Java Applet and Java Applet’s own sandbox mechanism. At that time, I sometimes found myself at the peak of being crazy or being collapsed.

So as I explain, asynchronous programming is not funny. And we would like to accept synchronous programming. Now let’s take a look at those Java synchronous programming which need to be JavaScript asynchronous programming:

Java snippet:

Display display = Display.getDefault();
SimpleSWTRPC shell = new SimpleSWTRPC(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) { // waiting loop
if (!display.readAndDispatch())
display.sleep();
}
// continue other codes...

But in JavaScript, the above waiting loop will use up all CPU times and freeze browser. So such waiting loop must be avoided. And callback mechanism is used:

var display = $wt.widgets.Display.getDefault ();
var shell = new org.java2script.demo.simplerpc.SimpleSWTRPC (display, 1264);
shell.open ();
shell.layout ();
Sync2Async.block (shell, this, function () {
// continue other codes...
});

The above codes use Sync2Async technology. Such technologies have lots of defects. The biggest defect is that it can not stop browser to execute the following codes outside the method closure. For example, if the above codes are in method #openUpDialog, and in another method say #setUp call this method and then call other methods:

this.openUpDialog();
this.checkState();
this.sendOutRequest();

When the above codes are executed in Java mode, #checkState and #sendOutRequest will never be called until user closes the dialog. But in JavaScript Sync2Async mode, the callback technology can not block browser from executing #checkState and #sendOutRequest, which may result in incorrect result. This is the key defect of Sync2Async technology. Even though it has defects, such technology helps developes a lots for some simple tasks.

In order to fulfill some complicate task, designers should design the whole architecture as asynchronous programming patter from the beginning. Even in Java language, all things in asynchronous mode are still difficult.

More should be discussed for this issue.

This entry was posted in Architecture, Hacks. Bookmark the permalink.

17 Responses to Asynchronous Programming

  1. Andrew Pelt says:

    I???m impressed, I must say. Really rarely do I encounter a blog that???s both educative and entertaining, and let me tell you, you have hit the nail on the head. Your idea is outstanding; the issue is something that not enough people are speaking intelligently about. I am very happy that I stumbled across this in my search for something relating to this.

  2. autobuildit review says:

    I definitely wanted to post a simple remark so as to appreciate you for those magnificent advice you are sharing on this site. My incredibly long internet investigation has finally been compensated with wonderful know-how to talk about with my friends. I ‘d repeat that many of us readers actually are really endowed to exist in a very good site with many brilliant individuals with insightful tips and hints. I feel very much lucky to have seen your entire web site and look forward to some more thrilling minutes reading here. Thanks once more for everything.

  3. Lyda Jollie says:

    I am looking for a great blogging website, but there are just too many! I am actually looking for a website that’s free and there can be many bloggers on one site. For example, I created a blog and people who I choose (friends and family) can easily start blogging on the site. If I could easily update it from my iPod touch that would be nice. And if I could personalize easily. (Have my own logo and background) Note this is not mandatory! Thank You’s ahead!.

  4. It’s perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I wish to suggest you some interesting things or suggestions. Maybe you could write next articles referring to this article. I wish to read more things about it!

  5. I’m a blog crazed individual and i adore to read cool weblog like yours.

  6. Devin Larosa says:

    I have been checking out many of your articles and i must say pretty good stuff. I will make sure to bookmark your website.

  7. Jessika says:

    Feel free to visit my site: web page (Jessika)

  8. seo traffic says:

    A lot of heavy search engine marketing graphics makes the grade of the price.
    So, search engine marketing by looking at the time and personalized information. Design services” provides variety of benefits. Houston web designers for assistance in as quick as a series of responses including confirmations. A business only gets one chance to work in the program you will need to remember is that?

    My site seo traffic

  9. Cheap Jordan 3,the sports shoes air jordans retro brand.

    Buy cheap jordans online all sizes for mens and women 5-13
    free shipping, try our fastest delivery globally! more from og retro jordans 3 gs

  10. Villa Blanca comped the meal and offered a complimentary glass a wine.
    s an a top notch Zumba instructor who can help you become in the greatest
    shape of your life. As the concept of living the swingers lifestyle is gaining social acceptance and respectability with
    the popularity of Swinger resorts is also increasing day by day.

  11. Rod says:

    Most of all, plan your repayment well so that you simply can certainly settling your financial obligations promptly Rod these
    payday lenders do not come up with a hard inquiry to your
    credit score, as other creditors do.

  12. Camilla says:

    Now, simply by going for their webpage, you can apply to
    get a a bad credit score loan web instantly know what form
    of interest rates and quotes it is possible to expect to deal with Camilla in your case, you must be considered a us
    citizen to be able to take advantage of the ultimate
    cash advance.

  13. quite vivid says:

    A combination of personal and business references is usually recommended quite vivid cash
    allows bills to get paid, payroll to get met, and capital improvements to fuel expansion.

  14. Allan Weder says:

    People http://weddinginvitations4u.net/invite:161774503675150188 come up to me and say, “Emo, do people really come up to you?”

  15. Marriage is that relation between man and woman in which the independence is equal, the dependence mutual, and the obligation reciprocal.

  16. Definitely Compared to the rest of SEA it is, but coming from a big city in USA it was The dollar is stronger than the yen right I would say $50 a day is a good Shop around places with airbnb, I found if you book the day of the prices are way

Leave a Reply

Your email address will not be published. Required fields are marked *