如何在Java中实现并行编程

时间:2014-10-12 17:24:40

标签: java parallel-processing

我们需要在JAVA中进行并行编程的库。

1 个答案:

答案 0 :(得分:1)

您只需使用Runnable构造函数使用Thread接口(或Java 8中的lambda函数)启动新线程。这是一个非常非常基本的例子:

Thread t = new Thread(() -> {
    System.out.println("I'm in a different thread from the other code in this example");
});
t.start();

然后,当然,你必须处理所有关于并发的问题,包括synchronized关键字,java.util.concurrent及其子包等各种事物(可能)等。

Java tutorial on this here

相关问题