Deadlock synchronously (String intern ())

I user sun jdk 1.5 ThreadPoolExecutor (24, 24.60, TimeUnit.SECONDS, new LinkedBlockingQueue ()). soemtime I use the jdb tool to find the status of all threads in a thread pool, "wait on monitor", code:

    String key = getKey(dt.getPrefix(), id);
    synchronized (key.intern()) {      ----->

Is there a problem in "synchronized (key.intern ())"?


I get the following informatnio using the jdb tool, the status of 24 threads is "waiting on the monitor", this means that 24 threads are deadlocked in "key.intern ()".

(java.lang.Thread) 0x28 pool-3-thread-2, waiting on the monitor

(java.lang.Thread) 0x27 pool-3-thread-3, waiting on the monitor

(java.lang.Thread) 0x1b pool-3-thread-4, waiting on the monitor

(java.lang.Thread) 0x1a pool-3-thread-5 is waiting on the monitor

(java.lang.Thread) 0x19 pool-3-thread-6, waiting on the monitor

(java.lang.Thread) 0x18 -3--7,

(java.lang.Thread) 0x17 pool-3-thread-8 ...

: Sting intern() , ?

+5
11

, : String?

, , : - bad .

+5

. , key.intern() , . String.intern() . key .

+4

, . , intern(), , .

, ( ), , , .

, .

+2

String, String ( ). : .

+2

. String. - .

String , , "" "where" .

, String. : " ". , .

, .

+2

, , . , , , , ( ), , , , , .

- , , .

.

+2

, key.intern() .

. , . intern() , , , .

+1

.

, . String.intern() , , JVM, . , , .

, "key.intern(), ". intern() , , .

  String s1 = new String(new char[] { 'c', 'o', 'm', 'm', 'o', 'n' }).intern();
  String s2 = new String("commo" + (s1.charAt(s1.length() - 1)).intern();
  String s3 = "common";
  if ((s1 == s2) && (s1 == s3))
    System.out.println("There only one object here.");

, , , .

, , . , , ..

+1

String.intern() . , "lock1", UUID : "85e565b3-d440-46e7-93b6-69ee7e9a63ee-lock1". . .

0

key.intern() , key.intern() String.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#intern()

public String intern() . , , String.

-1
source

String.intern () is a native method - this may be the cause of the problem.

-1
source

All Articles