Run with Java threads

0

I am looking for a way to run the following two lines of code with threads in parallel. I have seen some options, but they all go through to create a class Thread , but I can not create the class in this case. I'm not sure how I can create the two threads and run in parallel:

list.forEach(reviewsList -> {
    reviewWriter.persistReviews(reviewsList, activeTable);
});
saveInCoherence();

private void saveInCoherence() {
    reviewsMap.forEach((keyMap, reviewList) -> {
        ...
    }
}

In functional mode, what this will do is part go to Oracle and it will do inserts and the other part will go to a cache and cache the same thing. The issue is that the process takes too long and for that reason I would like to put threads so that both processes go in parallel.

    
asked by hector s. 10.10.2018 в 16:31
source

1 answer

0

You say that you can not create new classes, clearly it becomes more complicated, but not impossible, when I have to execute something in Threads , I create a Runnable

    ThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {

            try {
                functionToCall();
            } catch (Exception e) {
                LOG.error("Error to run task", e);
            }
        }
    };
    executor.execute(runnable);

I hope it serves you for what you need.

    
answered by 12.10.2018 / 16:32
source