Demos are run with JUnit
This commit is contained in:
parent
b27a8cff06
commit
4e3f9fa626
|
@ -52,6 +52,14 @@
|
|||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.baeldung.mdc.log4j;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.mdc.TransactionFactory;
|
||||
import com.baeldung.mdc.Transfer;
|
||||
|
||||
public class Demo {
|
||||
|
||||
@Test
|
||||
public void main() throws InterruptedException {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
TransactionFactory transactionFactory = new TransactionFactory();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Transfer tx = transactionFactory.newInstance();
|
||||
Runnable task = new Log4JRunnable(tx);
|
||||
executor.submit(task);
|
||||
}
|
||||
executor.shutdown();
|
||||
executor.awaitTermination(60, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.mdc.log4j2;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.mdc.TransactionFactory;
|
||||
import com.baeldung.mdc.Transfer;
|
||||
import com.baeldung.mdc.log4j.Log4JRunnable;
|
||||
import com.baeldung.mdc.log4j2.Log4J2Runnable;
|
||||
import com.baeldung.mdc.slf4j.Slf4jRunnable;
|
||||
|
||||
public class Demo {
|
||||
|
||||
@Test
|
||||
public void main() throws InterruptedException {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
TransactionFactory transactionFactory = new TransactionFactory();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Transfer tx = transactionFactory.newInstance();
|
||||
Runnable task = new Log4J2Runnable(tx);
|
||||
executor.submit(task);
|
||||
}
|
||||
executor.shutdown();
|
||||
executor.awaitTermination(60, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.mdc.slf4j;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.mdc.TransactionFactory;
|
||||
import com.baeldung.mdc.Transfer;
|
||||
import com.baeldung.mdc.log4j.Log4JRunnable;
|
||||
import com.baeldung.mdc.log4j2.Log4J2Runnable;
|
||||
import com.baeldung.mdc.slf4j.Slf4jRunnable;
|
||||
|
||||
public class Demo {
|
||||
|
||||
@Test
|
||||
public void main() throws InterruptedException {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
TransactionFactory transactionFactory = new TransactionFactory();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Transfer tx = transactionFactory.newInstance();
|
||||
Runnable task = new Slf4jRunnable(tx);
|
||||
executor.submit(task);
|
||||
}
|
||||
executor.shutdown();
|
||||
executor.awaitTermination(60, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue