교착 상태에 대한 아래 midlet 코드 (클래스 Moo)의 간단한 부분 (최소한 스레드 here에서이 게시물을 읽은 후 교착 상태로 가정).j2me 네트워킹, 스레드 및 교착 상태
나는 게시물에서 관련 발췌를 재현 : 문제의
String url = ...
Connection conn = null;
try {
conn = Connector.open(url);
// do something here
}
catch(IOException e){
// error
}
뿌리는 오픈() 호출의 차단 특성이다. 일부 플랫폼에서는 시스템이 별도의 스레드에 해당하는 실제 연결을 덮개 아래에서 수행합니다. 호출 스레드는 연결 스레드가 연결을 만들 때까지 차단됩니다. 동시에 보안 하위 시스템에서는 사용자가 연결을 확인하도록 요구할 수 있으며 연결 스레드는 이벤트 스레드가 사용자로부터 확인을받을 때까지 차단됩니다. 교착 상태는 이벤트 스레드가 이미 연결 스레드를 기다리고 있기 때문에 발생합니다. 시스템 스레드 호출이 여기 다 (이벤트 및 알림 스레드)와 교착 상태에 이르는 일련의 이벤트 방법
public class Moo extends MIDlet {
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Display display = Display.getDisplay(this);
MyCanvas myCanvas = new MyCanvas();
display.setCurrent(myCanvas);
myCanvas.repaint();
}
class MyCanvas extends Canvas {
protected void paint(Graphics graphics) {
try {
Image bgImage = Image.createImage(getWidth(), getHeight());
HttpConnection httpConnection = (HttpConnection) Connector
.open("http://stackoverflow.com/content/img/so/logo.png");
Image image = Image.createImage(httpConnection
.openInputStream());
bgImage.getGraphics().drawImage(image, 0, 0, 0);
httpConnection.close();
graphics.drawImage(bgImage, 0, 0, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
은 누군가가 말해 주시겠습니까. 교착 상태로 이어질 수있는 스레드가 무엇인지 명확하지 않습니다.
- j2me 스레드 모델에 대한 문서가 있습니까?
- 어디에서 j2me 시스템 클래스의 소스를 얻을 수 있습니까? (연결 클래스의 구현을 확인하고 싶습니다)?
편집 : 위의 코드에서 나는 논리를 얻습니다. 그러나 아래 코드는 적어도 올바르게 작동해야합니까? 이것은 또한 별도의 스레드에서 네트워크 연결을하고있는 곳에서 교착 상태가됩니다.
public class Foo extends MIDlet {
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
Display display = Display.getDisplay(this);
MyCanvas myCanvas = new MyCanvas();
display.setCurrent(myCanvas);
myCanvas.repaint();
}
class MyCanvas extends Canvas {
protected void paint(Graphics graphics) {
try {
Image bgImage = Image.createImage(getWidth(), getHeight());
FetchImage fetchImage = new FetchImage();
Thread thread = new Thread(fetchImage);
thread.start();
thread.join();
bgImage.getGraphics().drawImage(fetchImage.image, 0, 0, 0);
graphics.drawImage(bgImage, 0, 0, 0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class FetchImage implements Runnable {
public Image image;
public void run() {
HttpConnection httpConnection;
try {
httpConnection = (HttpConnection) Connector
.open("http://10.4.71.200/stage/images/front/car.png");
image = Image.createImage(httpConnection.openInputStream());
httpConnection.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
훌륭한 질문과 답변, 특별히이 스레딩 작업에 대해 명확성을 원한다면. – Sydwell