newFixedThreadPool.setCorePoolSize()不使用线程,创建新的theads.
说明:我为size2创建了一个newFixedThreadPool,如果这个池的两个线程都忙,我使用setCorePoolSize()向这个池添加两个线程.在这个过程中它似乎没有重用线程或者可能正在终止一些线程并创建新的,我将用代码解释.
public class IncreasePoolSize
{
static ExecutorService service = null;
public static void main(String[] args) throws JMSException, InterruptedException
{
int NoOfth = 2;
int noOfTimesToInc = 0;
System.out.println("Start");
service = Executors.newFixedThreadPool(NoOfth);
for (;;)
{
if ( ((ThreadPoolExecutor)service).getActiveCount() >= NoOfth )
{
if (noOfTimesToInc < 1)
{
System.out.println("Increased Threads-" + (noOfTimesToInc + 1) + " time(s)");
NoOfth += 2;
System.out.println("NoOfTh-" + NoOfth);
((ThreadPoolExecutor)service).setCorePoolSize(NoOfth);
System.out.println("Total no of theads after increasing-" + ((ThreadPoolExecutor)service).getCorePoolSize());
noOfTimesToInc++;
}
}
else if ( ((ThreadPoolExecutor)service).getActiveCount() <= …Run Code Online (Sandbox Code Playgroud) 我是 Cucumber 的新手并试图解决简单的问题:
我创建了一个 Java 项目并将所有与黄瓜相关的 jars 引用到该项目的构建路径(称为“CukeTest4”),下面是显示 java 文件和功能文件的结构。当我在 Eclipse 中将此功能文件作为 Cucumber 功能运行时,它运行良好。
现在,我想从另一个主要方法运行它。我创建了另一个 Java 项目,添加了一个带有 main 方法的类,下面的代码在默认包中。
import cucumber.api.cli.Main;
public class UseCukeFromMain {
public static void main(String[] args) throws Throwable
{
Main.main(new String[]{"-g", "C:/work/workspaces/neon2_wks_new1/Cuketest4/src/com/cuke", "C:/work/workspaces/neon2_wks_new1/Cuketest4/src/com/cuke/cukefeature.feature"});
}
}
Run Code Online (Sandbox Code Playgroud)
我已经在 java 文件中提供了该方法的实现,因为它在 Eclipse 中运行良好,但显示了下面的消息来实现该方法
[33mU[0m
1 Scenarios ([33m1 undefined[0m)
1 Steps ([33m1 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^I want to write a step with precondition$")
public void i_want_to_write_a_step_with_precondition() throws Throwable {
// Write code …Run Code Online (Sandbox Code Playgroud)