-1

In an enterprise back-end Java application, I have a requirement where some part of code calls various API which are independent of each other. On receiving response, I am utilizing them and passing data to requester.

For this, I have implemented callable based multi-threading (using Executor). But a colleague is stating that implementing multi-threading would make my code responsible for managing resources and not the Web App Container which can lead to performance issues.

So I wanted to know, what is the impact of implementing multi-threading in my code? And how can I make sure that resources are managed properly without impacting overall application.

damndemon
  • 331
  • 3
  • 11

1 Answers1

1

There are a some different aspectes mixed together in your question. Creating threads on an application server is not prohibited because it could cause performnce issues. It's more that the server itself is responsible to manage the system resources. Spawning own threads, of which the server is unaware of, can not be managed by the server. See this page for more info about the topic.

Using an thread-executor that is provided by the platform, is very valid an could be used to implement multi-threading nevertheless. See here for example.

Another aspect of multi-threading is indeed performance. Creating threads comes with a certain cost and creating too many of them may lead to an overhead in conext-switching. The trade-off between pralellism and having to manage a lot of threads has to be consireded by the developer. Again this is why application servers, manage their own thread-pools.

Sebastian
  • 1,642
  • 13
  • 26
  • So if server is unaware of new spawned thread, would it mean that resources would be ill managed? And what should I do in code to make sure that my threads resources are properly managed? – damndemon Feb 14 '19 at 11:13