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

org.bouncycastle.jcajce.provider.drbg.EntropyDaemon Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.

There is a newer version: 1.79
Show newest version
package org.bouncycastle.jcajce.provider.drbg;

import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

class EntropyDaemon
    implements Runnable
{
    private static final Logger LOG = Logger.getLogger(EntropyDaemon.class.getName());

    private final LinkedList tasks = new LinkedList();

    public EntropyDaemon()
    {
    }

    void addTask(Runnable task)
    {
        synchronized (tasks)
        {
            tasks.add(task);
        }
    }

    public void run()
    {
        while (!Thread.currentThread().isInterrupted())
        {
            Runnable task;
            synchronized (tasks)
            {
                task = tasks.poll();
            }

            if (task != null)
            {
                try
                {
                    task.run();
                }
                catch (Throwable e)
                {
                    // ignore
                }
            }
            else
            {
                try
                {
                    Thread.sleep(5000);
                }
                catch (InterruptedException e)
                {
                    Thread.currentThread().interrupt();
                }
            }
        }

        if (LOG.isLoggable(Level.FINE))
        {
            LOG.fine("entropy thread interrupted - exiting");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy