April 2015
Beginner to intermediate
494 pages
10h 26m
English
Let's create a native thread using the POSIX PThread API and attach it to the VM:
Store.cpp, include unistd.h, which gives access to the sleep() function:#include "Store.h"
#include <cstdlib>
#include <cstring>
#include <unistd.h>
...Implement startWatcher(). This method is executed from the UI thread. To do so, first instantiate and initialize a StoreWatcher structure.
pthread POSIX API:StoreWatcher* startWatcher(JavaVM* pJavaVM, Store* pStore,
jobject pLock) {
StoreWatcher* watcher = new StoreWatcher();
watcher->mJavaVM = pJavaVM;
watcher->mStore = pStore;
watcher->mLock = pLock;
watcher->mRunning = true;
...Then, initialize and launch ...