All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.leeonky.util.JavaCompilerPool Maven / Gradle / Ivy

package com.github.leeonky.util;

import com.github.leeonky.util.Suppressor;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.toCollection;

public class JavaCompilerPool {
    private final BlockingDeque workspaces;
    private final String generatePackage;

    public JavaCompilerPool(int maxCount, String generatePackage) {
        workspaces = IntStream.range(0, maxCount).boxed().collect(toCollection(LinkedBlockingDeque::new));
        this.generatePackage = generatePackage;
    }

    public JavaCompiler take() {
        return new JavaCompiler(generatePackage, Suppressor.get(workspaces::takeFirst));
    }

    public void giveBack(JavaCompiler compiler) {
        Suppressor.run(() -> workspaces.putLast(compiler.getId()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy