Home » Core Java » util » concurrent

concurrent

Semaphores example limiting URL connections

In this example we shall show you how to use a Semaphore for limiting URL connections. We have implemented a class, ConnectionLimiter that uses a Semaphore and is described below: It creates a new Semaphore with a given number of permits. It implements a method, URLConnection acquire(URL url). The method acquires a permit from this semaphore, blocking until one is ...

Read More »

Exchanger example passing logs to a background logger

With this example we are going to demonstrate how to create an Exchanger passing logs to a background logger. We have implemented a class, BackgroundLogger that implements the Runnable interface. In short the class is described below: It consists of a static class LogEntry, that has three fields, a long time, an int value and a Stringbuilder, and a static class LogEntries, ...

Read More »