-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
5.0, 6
-
None
-
generic
-
generic
In some applications, the same text is accessed by different clients within the
same JVM that have different locales. For example, in the JMX API a managed
object can have a description. The managed object can be accessed by several
remote clients, and those clients could have different locales. It would make
sense for the thread handling a remote client to be associated with that
client's locale, so that the managed object could tailor its description to
that locale. Different clients then see different descriptions. This is much
simpler than trying to push a Locale parameter through every method between the
code that knows the client's locale and all code that needs it.
This could be achieved by adding the following to java.util.Locale:
import java.util.concurrent.Callable;
private static final ThreadLocal<Locale> threadLocale =
new InheritableThreadLocal<Locale>();
public static Locale getThreadLocale() {
return threadLocale.get();
}
public static <V> V doWithThreadLocale(Locale locale, Callable<V> task)
throws Exception {
Locale oldLocale = getThreadLocale();
try {
threadLocale.set(locale);
return task.call();
} finally {
threadLocale.set(oldLocale);
}
}
Then a client handler can do something like this:
Object result =
Locale.doWithThreadLocale(clientLocale,
new Callable<Object>() {
public Object call() {
return handleClientRequest();
}
});
same JVM that have different locales. For example, in the JMX API a managed
object can have a description. The managed object can be accessed by several
remote clients, and those clients could have different locales. It would make
sense for the thread handling a remote client to be associated with that
client's locale, so that the managed object could tailor its description to
that locale. Different clients then see different descriptions. This is much
simpler than trying to push a Locale parameter through every method between the
code that knows the client's locale and all code that needs it.
This could be achieved by adding the following to java.util.Locale:
import java.util.concurrent.Callable;
private static final ThreadLocal<Locale> threadLocale =
new InheritableThreadLocal<Locale>();
public static Locale getThreadLocale() {
return threadLocale.get();
}
public static <V> V doWithThreadLocale(Locale locale, Callable<V> task)
throws Exception {
Locale oldLocale = getThreadLocale();
try {
threadLocale.set(locale);
return task.call();
} finally {
threadLocale.set(oldLocale);
}
}
Then a client handler can do something like this:
Object result =
Locale.doWithThreadLocale(clientLocale,
new Callable<Object>() {
public Object call() {
return handleClientRequest();
}
});
- relates to
-
JDK-4125164 Throwable.getLocalizedMessage() does not support multiple locales within one jav
-
- Closed
-