The IBM WebSphere application server, respectively, is running on the IBM JVM. The application works in several threads, both WebContainer and background processes. In a separate thread, I get all the threads that are running in this JVM, thus:

Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); for(Thread t: threadSet){ ... } 

Is it possible to somehow get a list of all objects, for example, the class java.sql.Connection, or its successors, and execute some query to the database on their behalf.

For example, several threads have their connections to the database and I need to know which SQL_ID is used by each thread.

Is it possible to implement it? Maybe there is another way to solve this problem?

  • one
    It sounds as if you are trying to solve some problem is fundamentally wrong. What is the ultimate goal? - Nofate
  • The ultimate goal is to get a list of connections to the database for each of my stream. After that, you need to know the SID (of course Oracle SID, and not SQL_ID is a typo in the first message). - Mikhael-VK
  • Another thought was to make your MyConnection implements Connection and when the connection is created, put the necessary information into the card, then read it if necessary. - Mikhael-VK
  • And how do threads "own" these compounds? Are they wrapped in ThreadLocal ? Still, in the general case, instances of classes and threads that call methods on them are orthogonal to each other and do not consist in a has-a relationship. - Nofate
  • The task is all complicated and complicated. In WebSphere there is a ConnectionPool, the connection is naturally not ThreadLocal. The java thread itself receives only a wrapper and executes the request through it. Only WebSphere knows about the real connection. - Mikhael-VK

0