mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-05-11 22:52:11 +02:00
27 lines
501 B
Java
27 lines
501 B
Java
|
|
import java.util.concurrent.Semaphore;
|
|
|
|
class SemaphoreClass {
|
|
private final Semaphore sem = new Semaphore(1);
|
|
|
|
public void test() {
|
|
//ez állítja meg a threadet
|
|
sem.acquire();
|
|
|
|
//ez ad egy futást hozzá
|
|
sem.release();
|
|
}
|
|
}
|
|
|
|
class SemaphoreLimit {
|
|
private final Semaphore sem = new Semaphore(15, true);
|
|
|
|
public void search() {
|
|
sem.acquire();
|
|
//keres
|
|
//így egyszerre csak 15 thread kereshet
|
|
sem.release();
|
|
}
|
|
}
|
|
|