如何在单独的线程中运行Java进程

时间:2018-08-23 15:50:59

标签: java unit-testing selenium-webdriver ui-automation

我有一个测试应用程序。它有一个用Java编写的模拟服务。我需要在单独的线程中继续在整个测试套件中运行此服务。除此之外,我还需要在执行测试之前迷失这项服务,并且测试也是用java和testng编写的。

2 个答案:

答案 0 :(得分:2)

如果要使用太多线程,那么最好的方法是使用如下所示的Java executor服务。

ExecutorService executorService = Executors.newFixedThreadPool(10);

executorService.execute(new Runnable() {
public void run() {
    //Start your mock service
    }
});

executorService.shutdown();

答案 1 :(得分:1)

如果您能够在应用程序中使用Thread,我建议使用lambda以便在新线程new Thread(() -> yourMethod()).start();中运行特定方法

相关问题