小编use*_*022的帖子

将类文件作为与java代码分开的进程运行

public static void main(String args[]) throws IOException
{
    Process p = Runtime.getRuntime().exec("java E:/workspace/JNIProgram/src/JNIProgram.class");
}   
Run Code Online (Sandbox Code Playgroud)

所以我有这个代码,我正在尝试运行JNIProgram.class文件,但程序立即终止而不做其工作(这是创建一个新的txt文件并写入它)

那么我做错了什么

java class process runtime.exec

1
推荐指数
1
解决办法
2420
查看次数

为什么线程会减慢程序的执行速度?

我有一些代码可以利用并行性来提高效率.由于我的PC有双处理器,我尝试在两个线程上运行代码.所以我写了下面的代码(这是一个非常简化的版本):

Evaluator::evaluate(vector<inpType> input, bool parallel) {
    std::thread t0;
    if(parallel) {
        // Evaluate half of the input in a spawned thread
        t0 = std::thread(&Evaluator::evaluatePart, this, std::ref(input), 0, input.size()/2 + input.size()%2);
        // Evaluate the other half of the input in this thread
        evaluatePart(input, input.size()/2 + input.size()%2 - 1, input.size()/2);
    } else {
        // sequential evaluate all of the input
        evaluatePart(input, 0, input.size());
    }
    // some other code

    // after finishing everything join the thread
    if(parallel) t0.join();
}

Evaluator::evaluatePart(vector<inpType> &input, int start, int …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading

1
推荐指数
1
解决办法
273
查看次数

标签 统计

c++ ×1

class ×1

java ×1

multithreading ×1

process ×1

runtime.exec ×1