This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TimePrinter { | |
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss"); | |
private static final Logger LOGGER = LoggerFactory.getLogger(TimePrinter.class.getName()); | |
public void reportCurrentTime() { | |
LOGGER.info("The time is now " + DATE_FORMAT.format(new Date())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableScheduling | |
@ComponentScan("pl.mjedynak") | |
public class AppConfig { | |
@Bean | |
public ScheduledTask scheduledTask() { | |
return new ScheduledTask(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App { | |
public static void main(String[] args) { | |
new AnnotationConfigApplicationContext(AppConfig.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(classes = AppConfig.class) | |
public class ScheduledTaskIntegrationTest { | |
@Test | |
public void shouldInvokeTask() { | |
Callable<Boolean> threadWithNameExists = | |
() -> getAllStackTraces().keySet().stream(). | |
anyMatch(t -> t.getName().equals(ScheduledTask.THREAD_NAME)); | |
await().until(threadWithNameExists, is(true)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> | |
<bean name="/AppConfig" class="pl.mjedynak.AppConfig" /> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Reader implements Runnable { | |
private final BlockingQueue<String> queue; | |
private final CountDownLatch latch; | |
public Reader(BlockingQueue<String> queue, CountDownLatch latch) { | |
this.queue = queue; | |
this.latch = latch; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LineProcessor implements Runnable { | |
private final PrimeFactorCounter primeFactorCounter = new PrimeFactorCounter(); | |
private final BlockingQueue<String> inputQueue; | |
private final BlockingQueue<String> successQueue; | |
private final BlockingQueue<String> exceptionsQueue; | |
private final CountDownLatch inputLatch; | |
private final CountDownLatch outputLatch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Writer implements Runnable { | |
private final String fileName; | |
private final BlockingQueue<String> queue; | |
private final CountDownLatch latch; | |
public Writer(BlockingQueue<String> queue, CountDownLatch latch, String fileName) { | |
this.queue = queue; | |
this.fileName = fileName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Bootstrap { | |
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |
private static final int THREAD_POOL_SIZE = 4; | |
static final String PRIME_FACTOR_FILE = "primeFactorCounter-threadPool.txt"; | |
static final String EXCEPTIONS_FILE = "exceptions-threadPool.txt"; | |
static final String SUMMARY_FILE = "summary-threadPool.txt"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadPoolSystemTest { | |
@Before | |
public void setUp() { | |
new File(Bootstrap.PRIME_FACTOR_FILE).delete(); | |
new File(Bootstrap.EXCEPTIONS_FILE).delete(); | |
new File(Bootstrap.SUMMARY_FILE).delete(); | |
} | |
@Test |
OlderNewer