Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite size of Threads.asyncJobs #264

Open
roneigebert opened this issue Apr 12, 2019 · 6 comments
Open

Infinite size of Threads.asyncJobs #264

roneigebert opened this issue Apr 12, 2019 · 6 comments

Comments

@roneigebert
Copy link
Member

I think we have a problem in asyncJobs queue.
I see that this queue is used in shutdown, but, executorService.awaitTermination can be a good alternative, right?

@RunWith(KikahaRunner.class)
public class ThreadsTest {

    Threads threads = Threads.elasticPool();

    final AtomicInteger counter = new AtomicInteger(0);
    final int numberOfRunnables = 1000000;

    @Test
    @SneakyThrows
    public void testThreads(){
        int i = 0;
        while ( i++ < numberOfRunnables )
            threads.submit( counter::incrementAndGet );
        Thread.sleep( 2000 );
        val asyncJobsField = threads.getClass().getDeclaredField( "asyncJobs" );
        asyncJobsField.setAccessible( true );
        val asyncJobs = (Queue)asyncJobsField.get( threads );
        assertEquals( numberOfRunnables, counter.get() );
        assertEquals( 0, asyncJobs.size() ); // test fails here - size is 1000000!
    }

}
@miere
Copy link

miere commented Apr 14, 2019 via email

@roneigebert
Copy link
Member Author

Hi, I'm fine and you?

I used the Threads.elasticPool() to run user routines in background (thousands of things every hour) and I had memory problems in the app (heap space). I saw the queue is never clean (only on shutdown) and I think this might have favoured my app memory problems (heap space). Currently I changed the code to use a own thread pool.

@miere
Copy link

miere commented Apr 15, 2019 via email

@miere
Copy link

miere commented Feb 7, 2021

@roneigebert any thoughts?

@roneigebert
Copy link
Member Author

Hi @miere! Well, I created a custom thread pool to solve this problem. But, if you agree we can improove the "kikaha threads" to clean everything after the thread execution with a TRY-FINALLY block

@miere
Copy link

miere commented Feb 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants