3

I have a Multithreading application, so I implemented ExecutorService with a Pool Size of 5 Threads

public class SimpleThreadPool {    
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
          Runnable worker = new WorkerThread("" + i);
          executor.execute(worker);
        }
        executor.shutdown();
        while (!executor.isTerminated()) {
        }
        System.out.println("Finished all threads");
    }
}

The application will be deployed in Websphere Web server in with settings contain a Thread Pool configuration : Application servers > > Thread Pools > Default, the Maximum Size is set to 60.

My question is, which Pool size configuration is taken, does the configuration in Websphere override the one in the code(5 threads) ?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
Bill
  • 205
  • 2
  • 3
  • 14
  • Your question does not make sense to me. Can you clarify abit more? – Minh Kieu Jun 21 '17 at 12:59
  • If you find my answer helpful - can you consider accepting it? – GhostCat Jun 22 '17 at 09:27
  • 1
    And unrelated: such "empty" loops : `while (!executor.isTerminated()) { }` are **dangerous**. You are doing "hot" waiting here; this means the CPU will be spinning 100% waiting for the condition to become true - it will make billions of calls to that method within a few seconds. You really want to put some "sleep(xxx)" call into the loop body here! – GhostCat Jun 22 '17 at 09:29
  • It's more like what kind of relation exists between the 60 threads created by Websphere, and the 5 threads used internally in the code. – Bill Jun 22 '17 at 09:40
  • @GhostCat I appreciate your replies, I don't see how can I upvote your responses, as I already did it for both o you. – Bill Jun 29 '17 at 14:10
  • @GhostCat as for the earlier question, do you have any idea what kind of relation exists between the 60 threads created by Websphere, and the 5 threads used internally in the code Is it like this: each Websphere Thread treating one demand gonna initiate 5 internal green threads ? – Bill Jun 29 '17 at 14:12
  • Maybe I put that comment in the wrong place :-) – GhostCat Jun 29 '17 at 14:13
  • 1
    I think: there is no relation. Just different thread objects, managed by different pools. – GhostCat Jun 29 '17 at 14:14
  • @GhostCat There's no relation between both object types, but when server is fully charged, I can see 210 Thread count. Thought, the APM I use(Dynatrace) mix both types ! – Bill Jun 29 '17 at 14:20

2 Answers2

2

No, those will be differrent thread pools.

The one with 60 threads needs to be obatined via jndi service by name. Websphere thread pool is a bit different. For example, it has support of JTA (distributed) transactions. You can use JTA transactions only inside those special thread pools.

The local one will have 5 threads and is not affected by Websphere by any means. You can check number of threads by submitting a lot of tasks and then printing thread stacks via jstack or kill -3 command.

Andrey Cheboksarov
  • 649
  • 1
  • 5
  • 9
2

Those two things have nothing to do with each other.

The server setting is about threads used by the server. See the documentation:

Use this page to configure a group of threads that an application server uses. Requests are sent to the server through any of the HTTP transports. A thread pool enables components of the server to reuse threads to eliminate the need to create new threads at run time. Creating new threads expends time and resources.

Now, your application code creates its own independent thread pool.

Which has nothing to do with that system pool.

Of course, it might be possible for your application to send "tasks" to that system thread pool; making use of it that way.

GhostCat
  • 137,827
  • 25
  • 176
  • 248