IOBound 작업을 실행하는 SwingWorker 스레드가 있는데,이 스레드는 실행되는 동안 인터페이스를 완전히 잠그고 있습니다. 카운터 루프에 대한 일반 작업 부하를 교체하면 동일한 결과가 발생합니다. SwingWorker의는 다음과 같이 기본적으로 같습니다SwingWorker 스레드가 실행되는 동안 내 GUI가 응답하지 않는 이유는 무엇입니까?
public class BackupWorker extends SwingWorker<String, String> {
private static String uname = null;
private static String pass = null;
private static String filename = null;
static String status = null;
BackupWorker (String uname, String pass, String filename) {
this.uname = uname;
this.pass = pass;
this.filename = filename;
}
@Override
protected String doInBackground() throws Exception {
BackupObject bak = newBackupObject(uname,pass,filename);
return "Done!";
}
}
JFrame의를 확장하는 클래스에서의 삶을 그것을 개막 코드 :
: 이public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if (BACKUP.equals(cmd)) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final StatusFrame statusFrame = new StatusFrame();
statusFrame.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
statusFrame.beginBackup(uname,pass,filename);
}
});
}
});
}
}
여기 StatusFrame의 흥미로운 부분이다
public void beginBackup(final String uname, final String pass, final String filename) {
worker = new BackupWorker(uname, pass, filename);
worker.execute();
try {
System.out.println(worker.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
내가 볼 수있는 한, "장기 실행"되는 모든 것은 작업자와 EDT의 GUI에 닿는 모든 것이 처리됩니다. 나는 어딘가에 물건을 얽힌 적이 있습니까, 아니면 너무 많은 SwingWorker를 기대합니까?
여기에서 저를 버렸던 것은'get()'에'while (! worker.isDone()) '을 앞에두고 동일한 응답이없는 것을 보았습니다. 'StatusFrame'이 끝나기 전에 GUI가 잠겨있는 것을보고 있었는데, 그때 못생긴'Runnable' 중첩을 시도했습니다. 그 문제는 지금 당장 의문입니다. – Starchy