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

AsyncFunc spawns new thread for each apply() call #324

Closed
g4s8 opened this issue Jul 19, 2017 · 11 comments
Closed

AsyncFunc spawns new thread for each apply() call #324

g4s8 opened this issue Jul 19, 2017 · 11 comments

Comments

@g4s8
Copy link
Contributor

g4s8 commented Jul 19, 2017

Creating new threads is expensive operation because it allocates a lot of memory, performs system-calls and register descriptors.
It would be better to create Executors.newCachedThreadPool() for async task (or maybe accept Executor as constructor argument) and submit tasks to it:

private final Executor exec = Executors.newCachedThreadPool();

@Override
public Future<Y> apply(final X input) {
    return this.exec.submit(
        () -> this.func.apply(input)
    );
}
@g4s8
Copy link
Contributor Author

g4s8 commented Jul 20, 2017

Looks like it was partially fixed in #330

@yegor256
Copy link
Owner

@0crat in

@0crat
Copy link
Collaborator

0crat commented Jul 20, 2017

@0crat in (here)

@yegor256 Job gh:yegor256/cactoos#324 is in scope.

@0crat
Copy link
Collaborator

0crat commented Jul 20, 2017

Job gh:yegor256/cactoos#324 assigned to @fabriciofx, please go ahead.

@yegor256
Copy link
Owner

@rultor release, tag is 0.11.7

@rultor
Copy link
Collaborator

rultor commented Jul 20, 2017

@rultor release, tag is 0.11.7

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Collaborator

rultor commented Jul 20, 2017

@rultor release, tag is 0.11.7

@yegor256 Done! FYI, the full log is here (took me 10min)

@yegor256
Copy link
Owner

yegor256 commented Jul 21, 2017

@g4s8 the problem seems to be fixed?

@g4s8
Copy link
Contributor Author

g4s8 commented Jul 21, 2017

@yegor256 sure, thanks

@g4s8 g4s8 closed this as completed Jul 21, 2017
@0crat
Copy link
Collaborator

0crat commented Jul 21, 2017

Job gh:yegor256/cactoos#324 is out of scope.

@0crat
Copy link
Collaborator

0crat commented Jul 21, 2017

+30 points just awarded to @fabriciofx, total is +60

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

4 participants