由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 问个面试题, 谢谢
相关主题
thread safe Singleton 的几种方法?Java concurrency的疑惑,难道我理解错了? (转载)
关于new operator的问题anyone saw this on code?
synchronization for counters刚刚开始学习java,麻烦帮我看一下我哪里错了行吗?谢谢
让大家了解工业界Java/J2EE面试题的难度what is your opinion in this case?
synchronization 锁住了什么?a question regarding spring collection initialization
The best HashMap Cache solutionwhy is this necessary?
跪求大牛指点Java,看不懂什么意思。java多线程问题请教
请教:怎么把synchronize的method改成用thread 但thread safe呢?Re: connection pool
相关话题的讨论汇总
话题: object话题: private话题: public话题: class
进入Java版参与讨论
1 (共1页)
b****u
发帖数: 1130
1
看到一个奇特的类, 想请教.
public class SpecialClass{
private A a;
private boolean b;
private Object o;
public SpecialClass (A a) {
this.a = a;
}
synchronized Object z() {
if (!b) {
o = a.y();
b = true;
}
return o;
}
public interface A {
Object y();
}
}
1. 类的功能 干什么用
2. 如何generify这个类.
3如何提高在并发环境下性能
g**e
发帖数: 6127
2
这个是考lazy initialized singleton?

【在 b****u 的大作中提到】
: 看到一个奇特的类, 想请教.
: public class SpecialClass{
: private A a;
: private boolean b;
: private Object o;
: public SpecialClass (A a) {
: this.a = a;
: }
: synchronized Object z() {
: if (!b) {

q*********u
发帖数: 280
3

看到一个奇特的类, 想请教.
public class SpecialClass{
private A a;
private boolean b;
private T o;
public SpecialClass (A a) {
this.a = a;
}
synchronized T z() {
if (!b) {
o = a.y();
b = true;
}
return o;
}
public interface A {
T y();
}
}
1. 类的功能 干什么用
Factory
2. 如何generify这个类.
3如何提高在并发环境下性能
按singleton的标准写z()这个method.

【在 b****u 的大作中提到】
: 看到一个奇特的类, 想请教.
: public class SpecialClass{
: private A a;
: private boolean b;
: private Object o;
: public SpecialClass (A a) {
: this.a = a;
: }
: synchronized Object z() {
: if (!b) {

b****u
发帖数: 1130
4
十分感谢楼上两位,但一些细节还是不明白,不太确定如何用这个类.
需要有其他类, 如 class B implements SpecialClass.A, 用Class B 这个类实现接
口,对
吧?
另外我们可不可以理解SpecialClass 为 "AbstractSingleton"?

【在 q*********u 的大作中提到】
:
: 看到一个奇特的类, 想请教.
: public class SpecialClass{
: private A a;
: private boolean b;
: private T o;
: public SpecialClass (A a) {
: this.a = a;
: }
: synchronized T z() {

m******t
发帖数: 2416
5
This looks more like a simple and naive cache implementation to me.

【在 b****u 的大作中提到】
: 看到一个奇特的类, 想请教.
: public class SpecialClass{
: private A a;
: private boolean b;
: private Object o;
: public SpecialClass (A a) {
: this.a = a;
: }
: synchronized Object z() {
: if (!b) {

s******e
发帖数: 493
6
Hard to say what this class is for.
But the main purpose of the whole things seems to guarantee that
o = a.y();
will be called only once for the delegated class object A.
It is kind of lazy initialization of Object O. Of course o can be used as a
cache object or whatever.
g*****g
发帖数: 34805
7
+1, a cache assuming object initialization is heavy.
For the most efficient implementation, check memorizer
in "Java Concurrency in Practice"

【在 m******t 的大作中提到】
: This looks more like a simple and naive cache implementation to me.
q*********u
发帖数: 280
8
yeah, an excellent book

+1, a cache assuming object initialization is heavy.
For the most efficient implementation, check memorizer
in "Java Concurrency in Practice"

【在 g*****g 的大作中提到】
: +1, a cache assuming object initialization is heavy.
: For the most efficient implementation, check memorizer
: in "Java Concurrency in Practice"

1 (共1页)
进入Java版参与讨论
相关主题
Re: connection poolsynchronization 锁住了什么?
这道题该走什么路The best HashMap Cache solution
Re: 谁有Java或Oracle的毒招 ?跪求大牛指点Java,看不懂什么意思。
Can Java thread return a value?请教:怎么把synchronize的method改成用thread 但thread safe呢?
thread safe Singleton 的几种方法?Java concurrency的疑惑,难道我理解错了? (转载)
关于new operator的问题anyone saw this on code?
synchronization for counters刚刚开始学习java,麻烦帮我看一下我哪里错了行吗?谢谢
让大家了解工业界Java/J2EE面试题的难度what is your opinion in this case?
相关话题的讨论汇总
话题: object话题: private话题: public话题: class