dhchen
dhchen

Reputation: 1198

Will ExecutorService.newFixedThreadPool.submit(new class()) cause memory leak?

I'm trying to use ExecutorService.newFixedThreadPool to running several tasks. Every time I submit to ExecutorService, I will new a class() which holds task related information.

Will it cause memory leak as time goes?

For example, will there be 1M classes if I submit() 1M times?

Upvotes: 3

Views: 587

Answers (1)

bmargulies
bmargulies

Reputation: 100152

No the executor service will not hold a reference beyond the lifetime of the task.

Upvotes: 2

Related Questions