3种写法对性能有多大影响
如果对于GenericUnregMenuDAO类事例化的问题,请高手指点,分别放在以下代码不同3个位置,请问,哪个位置声明比较合适?
package com.chinarainbow.otas.kernal.queue.OTAHandlers;
public class GetPushMsgHandler implements Runnable {
private static GetPushMsgHandler GetPushMsgHandlerProcess = null;
//第一个位置
private GenericUnregMenuDAO gum = new GenericUnregMenuDAO();
public static GetPushMsgHandler getInstance() {
while (true) {
if (GetPushMsgHandlerProcess != null) {
return GetPushMsgHandlerProcess;
} else {
try {
Thread.sleep(100);
GetPushMsgHandlerProcess = new GetPushMsgHandler();
} catch (InterruptedException e) {
}
}// end if
}
}
public void dataProc() {
//第二个位置
GenericUnregMenuDAO gum = new GenericUnregMenuDAO();
while(true){
//第三个位置
GenericUnregMenuDAO gum = new GenericUnregMenuDAO();
}
}
public void run() {
while (true) {
try {
dataProc();
} catch (Exception ex) {
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
}
}
[该贴被admin于2010-03-05 10:58修改过]
[该贴被admin于2010-04-29 09:50修改过]