I'm using a scheduled executor service
private ScheduledExecutorService pool = new ScheduledThreadPoolExecutor(1);
running a runnable at fixed rate
pool.scheduleAtFixedRate(new CoolRunnable(), 10, 10, TimeUnit.MILLISECONDS);
This thread pool waits that the previous execution finishes, but i'd like it to run the runnable every 10 milliseconds no matter whether the previous is done or not.
How can I do that?
EDIT: Fixed the problem replacing the MySQL connection with a connection pool. The normal connection methods are synchronized, that's why the runnables had to wait for each other.
To do that, you need to submit a task to an
ExecutorService
every 10s. ThisExecutorService
is the one that will take care of running the tasks:Using a cachedThreadPool will create new threads if older ones are still working. Careful in doing so: adding a new task every 10 seconds might create a lot of concurrent threads if the tasks take a lot longer to run.