Using background threads at porting
The previous recipe adds a GUI to the ported fusch
program with two issues left behind—unresponsiveness of the GUI and no progress update when processing is going on. This recipe discusses how to use a background thread to handle the
processing and report the progress to the main UI thread.
Getting ready
The sample program in this recipe is based on the program we developed in previous recipes of this chapter. You should go through them first. In addition, readers are recommended to reading the following recipes in Chapter 2, Java Native Interface:
Calling static and instance methods from the native code
Caching jfieldID, jmethodID, and reference data to improve performance
How to do it...
The following steps describe how to use a background thread for heavy processing and report progress update to the Java UI thread:
Copy the
PortingExecutableAUI
project that we developed in the previous recipe to a folder namedPortingExecutableAUIAsync
. Open the project in...