2024-06-12
This commit is contained in:
45
Writerside2/topics/Thread.md
Normal file
45
Writerside2/topics/Thread.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Thread
|
||||
|
||||
```java
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
jFrame.setVisible(true);
|
||||
});
|
||||
```
|
||||
|
||||
* `SwingUtilities.isEventDispatchThread()`
|
||||
|
||||
|
||||
## Swing Worker
|
||||
|
||||
SwingWorker의 첫 번째 제너릭은 `doInBackground()`의 반환 타입입니다.
|
||||
두 번째 제너릭은 `publish()`와 `process()`가 서로 주고 받는 데이터 타입입니다.
|
||||
|
||||
* **doInBackground()** : 백그라운드에서 작업을 처리합니다.
|
||||
* **done()** : 백그라운드 작업이 끝난 직후에 이벤트 디스패치 스레드에서 실행됩니다.
|
||||
* **publish()** : 백그라운드 작업 도중, 중간 결과를 내보냅니다. 이벤트 디스패치 스레드에서 **process()**가 호출됩니다.
|
||||
|
||||
|
||||
* `get()` / `get(long,TimeUnit)`
|
||||
* `setProgress()`
|
||||
* `SwingWorker.StateValue getState()`
|
||||
* `isCancelled()` / `isDone()`
|
||||
|
||||
|
||||
## Swing Timer
|
||||
|
||||
타이머는 지연 시간 이후에 이벤트 디스패치 스레드에서 액션을 실행합니다.
|
||||
|
||||
```java
|
||||
final Timer timer = new Timer(0, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
timer.start();
|
||||
```
|
||||
|
||||
* `getDelay()` / `setDelay(long)`
|
||||
* `getInitialDelay()` / `setInitialDelay(long)`
|
||||
* `isRepeats()` / `setRepeats(boolean)`
|
||||
* `start()` / `restart()` / `stop()`
|
||||
Reference in New Issue
Block a user