public synchronized static MyApplication getInstance() {
if (instance == null) {
synchronized (MyApplication .class) {
if (instance == null) {
instance = new MyApplication ();
}
}
}
return instance;
}
private class reUploadThread extends Thread {
@Override
public void run() {
while (true) {
upload();
}
try {
Thread.sleep(1000); //1s
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private void upload() {
synchronized (MyApplication .class) {
socket = new Socket(“192.1680.8”, “8080”);//当socket连接阻塞时程序,就会因为抢同步锁卡死
}
}