提交 05475bfe 编写于 作者: oldratlee's avatar oldratlee 🔥

update AgentDemo

上级 cafb0616
......@@ -112,7 +112,7 @@
<mainClass>com.oldratlee.mtc.threadpool.agent.AgentDemo</mainClass>
<classpathScope>test</classpathScope>
<arguments>
<argument>-javaagent:${artifactId}-${version}.jar</argument>
<argument>-javaagent:${build.directory}/${artifactId}-${version}.jar</argument>
</arguments>
</configuration>
</plugin>
......
......@@ -5,17 +5,48 @@ import com.oldratlee.mtc.Task;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author ding.lid
*/
public class AgentDemo {
static ExecutorService executorService = Executors.newFixedThreadPool(3);
static ExecutorService executorService = Executors.newFixedThreadPool(3, new ThreadFactory() {
AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
String name = "thread " + counter.getAndIncrement();
System.out.println(name);
Thread thread = new Thread(r, name);
thread.setDaemon(true);
return thread;
}
});
static {
for (int i = 0; i < 10; ++i) {
executorService.execute(new Runnable() {
@Override
public void run() {
System.out.println("Warm task!");
}
});
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("Warmed!");
}
public static void main(String[] args) throws Exception {
System.out.println("Hello, " + AgentDemo.class.getName());
MtContext.getContext().set("key7", "value7");
Task task = new Task("1");
......@@ -24,8 +55,10 @@ public class AgentDemo {
executorService.shutdown();
executorService.awaitTermination(3, TimeUnit.MINUTES);
assert "value7".equals(task.copiedContext.get("key7"));
System.out.println("OK");
if ("value7".equals(task.copiedContext.get("key7")))
System.out.println("OK");
else {
System.err.println("!!!!Fail!!!!");
}
}
}
......@@ -3,11 +3,11 @@
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{5}: %m%n" />
<param name="ConversionPattern" value="%d %t %5p %c{2} - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<level value="DEBUG" />
<appender-ref ref="CONSOLE" />
</root>
</log4j:configuration>
\ No newline at end of file
</log4j:configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册