This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 2ffb44549d Use Thread subclass instead of Closure in Console(closes
#2084)
2ffb44549d is described below
commit 2ffb44549db3273bd9eb61a7c1ae2a36d4edff1d
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Sep 7 01:06:15 2024 +0800
Use Thread subclass instead of Closure in Console(closes #2084)
---
.../main/groovy/groovy/console/ui/Console.groovy | 90 +++++++++++-----------
1 file changed, 47 insertions(+), 43 deletions(-)
diff --git
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index c78aac38e0..bfd65c36ec 100644
---
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -1363,55 +1363,59 @@ class Console implements CaretListener,
HyperlinkListener, ComponentListener, Fo
// Kick off a new thread to do the evaluation
// Run in a thread outside of EDT, this method is usually called
inside the EDT
- runThread = Thread.start {
- try {
- systemOutInterceptor.setConsoleId(this.getConsoleId())
- // TODO should systemErrorInterceptor receive the console id,
too?
- SwingUtilities.invokeLater { showExecutingMessage() }
- if (beforeExecution) {
- beforeExecution()
- }
- Tuple2<Object, Long> resultAndElapsedTime
- if (useScriptClassLoaderForScriptExecution) {
- ClassLoader savedThreadContextClassLoader =
Thread.currentThread().contextClassLoader
- try {
- Thread.currentThread().contextClassLoader =
shell.classLoader
+ runThread = new Thread() {
+ @Override
+ void run() {
+ try {
+ systemOutInterceptor.setConsoleId(this.getConsoleId())
+ // TODO should systemErrorInterceptor receive the console
id, too?
+ SwingUtilities.invokeLater { showExecutingMessage() }
+ if (beforeExecution) {
+ beforeExecution()
+ }
+ Tuple2<Object, Long> resultAndElapsedTime
+ if (useScriptClassLoaderForScriptExecution) {
+ ClassLoader savedThreadContextClassLoader =
Thread.currentThread().contextClassLoader
+ try {
+ Thread.currentThread().contextClassLoader =
shell.classLoader
+ resultAndElapsedTime = doRun(selected, st, record)
+ }
+ finally {
+ Thread.currentThread().contextClassLoader =
savedThreadContextClassLoader
+ }
+ } else {
resultAndElapsedTime = doRun(selected, st, record)
}
- finally {
- Thread.currentThread().contextClassLoader =
savedThreadContextClassLoader
+ if (afterExecution) {
+ afterExecution()
+ }
+ SwingUtilities.invokeLater {
finishNormal(resultAndElapsedTime.v1, resultAndElapsedTime.v2) }
+ } catch (Throwable t) {
+ if (t instanceof StackOverflowError) {
+ // set the flag that will be used in printing
exception details in output pane
+ stackOverFlowError = true
+ clearOutput()
+ }
+ SwingUtilities.invokeLater { finishException(t, true) }
+ } finally {
+ runThread = null
+ scriptRunning = false
+ interruptAction.enabled = false
+ systemOutInterceptor.removeConsoleId()
+ if (loopMode) {
+ int delay = prefs.getInt('loopModeDelay',
ConsolePreferences.DEFAULT_LOOP_MODE_DELAY_MILLIS)
+ Timer timer = new Timer(delay, {
+ if (inputAreaContentHash ==
inputArea.getText().hashCode()) {
+ runScriptImpl(selected, st)
+ }
+ })
+ timer.repeats = false
+ timer.start()
}
- } else {
- resultAndElapsedTime = doRun(selected, st, record)
- }
- if (afterExecution) {
- afterExecution()
- }
- SwingUtilities.invokeLater {
finishNormal(resultAndElapsedTime.v1, resultAndElapsedTime.v2) }
- } catch (Throwable t) {
- if (t instanceof StackOverflowError) {
- // set the flag that will be used in printing exception
details in output pane
- stackOverFlowError = true
- clearOutput()
- }
- SwingUtilities.invokeLater { finishException(t, true) }
- } finally {
- runThread = null
- scriptRunning = false
- interruptAction.enabled = false
- systemOutInterceptor.removeConsoleId()
- if( loopMode ) {
- int delay = prefs.getInt('loopModeDelay',
ConsolePreferences.DEFAULT_LOOP_MODE_DELAY_MILLIS)
- Timer timer = new Timer(delay, {
- if( inputAreaContentHash ==
inputArea.getText().hashCode() ) {
- runScriptImpl(selected, st)
- }
- })
- timer.repeats = false
- timer.start()
}
}
}
+ runThread.start()
}
@CompileStatic