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

[ISSUE #9721] support MemoryLimitedLinkedBlockingQueue #9789

Merged
merged 1 commit into from
Mar 16, 2022
Merged

[ISSUE #9721] support MemoryLimitedLinkedBlockingQueue #9789

merged 1 commit into from
Mar 16, 2022

Conversation

loongs-zhang
Copy link
Member

see #9721 and #9722

@loongs-zhang loongs-zhang changed the title support MemoryLimitedLinkedBlockingQueue [ISSUE #9721] support MemoryLimitedLinkedBlockingQueue Mar 15, 2022
@loongs-zhang
Copy link
Member Author

public class FixedThreadPool implements ThreadPool {

    public static final String NAME = "fixed";

    @Override
    public Executor getExecutor(URL url) {
        String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
        int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS);
        int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES);
        return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,
                queues == 0 ? new SynchronousQueue<Runnable>() :
                        (queues < 0 ?
                                //here can be replace to MemoryLimitedLinkedBlockingQueue
                                //for example, limit the maximum memory used by this queue to 100MB
                                new LinkedBlockingQueue<Runnable>()
                                : new LinkedBlockingQueue<Runnable>(queues)),
                new NamedInternalThreadFactory(name, true), new AbortPolicyWithReport(name, url));
    }

}

like FixedThreadPool, we should also change it in CachedThreadPoolEagerThreadPool and LimitedThreadPool.

@loongs-zhang
Copy link
Member Author

We can even control the number of threads based on MemoryLimiter in the future !

Copy link
Contributor

@chickenlj chickenlj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chickenlj chickenlj merged commit 51361dd into apache:3.0 Mar 16, 2022
@loongs-zhang
Copy link
Member Author

:)

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

Successfully merging this pull request may close these issues.

3 participants