Asynchronous Programming

Just keep the comment back from Youngpup’s Managing complexity in asynchronous GUIs – Words
Comment URL:http://youngpup.net/2006/20060128022344/comments#c2089

I also thinking about asynchronous programming these days not only for JavaScript but also for Java.

These days, I dedicated in open source project Java2Script Pacemaker at Sourceforge.net. It will provide tookit to transform existed Java codes into JavaScript codes, including the possible UI widgets (Eclipse’ SWT). But one problem must to be solved is blocking and threads. AJAX, the essential part is “A” which is asynchronous programming. But what about asynchronous programming is brought into the Java’s object-oriented programming?

Already, Java programmer can use system native semaphoro or thread to implement blocking. For example, Java programmer will open a dialog and wait for response result:


1
2
3
4
5
6
Dialog dialog = new Dialog(...);
int result = dialog.open();
if (result == OK) {
String name = dialog.getUserName();
....
}

But in the asynchronous programming, it would be something like this:


1
2
3
4
5
6
7
8
9
10
11
final Dialog dialog = new Dialog(...);
dialog.register(new Runnable() {
public void run() {
int result = dialog.open();
if (result == OK) {
String name = dialog.getUserName();
....
}
}
}
// return here!

Once the Java codes is asynchronous-oriented, I think the Java codes can be exported into JavaScript codes directly by Java2Script Pacemaker.

But in fact, asynchronous programming or refactoring existed synchronous programmed libraries into asynchronous-oriented libraries will require times.

This entry was posted in Java, JavaScript. Bookmark the permalink.

Leave a Reply

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