http://bbs.51cto.com/thread-1316339-1-1.html
http://www.android100.org/html/201509/18/182761.html
https://developer.android.com/ndk/downloads/index.html ndk 下载
1.
gradle.properties android.useDeprecatedNdk=true
2.
defaultConfig {
applicationId "com.lxcay.ndkdemo"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
ndk {
moduleName = "NativeUtil" //生成的so名称
ldLibs "log" //Log打印
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}
3.
public class NativeUtil {
static {
System.loadLibrary("NativeUtil");//加载so名称
}
public native String getStringFromC();
}
4.
cd app/src/main
5.
javah -d jni -classpath D:\Users\Lixiangos0170\AppData\Local\Android\sdk\platforms\android-24\android.jar;..\..\build\intermediates\classes\debug com.lxcay.ndkdemo.NativeUtil
public class ThreadPool {
private static ExecutorService pool;
private ThreadPool() {
}
public static ExecutorService getInstance() {
if (null == pool) {
/**
* @corePoolSize - 池中所保存的线程数,包括空闲线程。
* @maximumPoolSize - 池中允许的最大线程数。
* @keepAliveTime - 当线程数大于核心时,此为终止前多余的空闲线程等待新任务的最长时间。
* @unit - keepAliveTime 参数的时间单位。
* @workQueue - 执行前用于保持任务的队列。此队列仅保持由 execute 方法提交的 Runnable 任务。
*/
//最多一个线程,最少1个线程,最多在队里中有2个任务
return new ThreadPoolExecutor(1, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(2));
}
return pool;
}
}