37
37
import java .util .HashMap ;
38
38
import java .util .Map ;
39
39
import java .util .Properties ;
40
+ import java .util .concurrent .Callable ;
41
+ import java .util .concurrent .ExecutionException ;
42
+ import java .util .concurrent .ExecutorService ;
43
+ import java .util .concurrent .Executors ;
44
+ import java .util .concurrent .Future ;
45
+ import java .util .concurrent .TimeUnit ;
46
+ import java .util .concurrent .TimeoutException ;
40
47
import java .util .logging .Level ;
41
48
import java .util .logging .Logger ;
49
+ import javax .swing .SwingUtilities ;
50
+ import org .openide .util .Utilities ;
42
51
import sun .tools .attach .HotSpotVirtualMachine ;
43
52
44
53
/**
@@ -51,6 +60,7 @@ class AttachModelImpl extends AttachModel {
51
60
private static final String HEAP_DUMP_NO_SPACE_ID = "No space left on device" ; // NOI18N
52
61
private static final String JCMD_VM_COMMAND_LINE = "VM.command_line" ; // NOI18N
53
62
static final Logger LOGGER = Logger .getLogger (AttachModelImpl .class .getName ());
63
+ private static final ExecutorService winExec = Executors .newCachedThreadPool ();
54
64
55
65
String pid ;
56
66
HotSpotVirtualMachine vm ;
@@ -60,13 +70,33 @@ class AttachModelImpl extends AttachModel {
60
70
pid = Integer .toString (app .getPid ());
61
71
}
62
72
63
- public synchronized Properties getSystemProperties () {
73
+ // see JmxModelImpl$LocalVirtualMachine.executeAndWait
74
+ private static <V > V executeAndWait (Callable <V > call ) {
75
+ if (Utilities .isWindows ()) {
76
+ Future <V > result = winExec .submit (call );
77
+ try {
78
+ return result .get (SwingUtilities .isEventDispatchThread () ? 5 : 25 , TimeUnit .SECONDS );
79
+ } catch (InterruptedException | ExecutionException | TimeoutException ex ) {
80
+ LOGGER .log (Level .INFO , "executeAndWait get" , ex ); // NOI18N
81
+ }
82
+ return null ;
83
+ }
64
84
try {
65
- return getVirtualMachine (). getSystemProperties ();
66
- } catch (IOException ex ) {
67
- LOGGER . log ( Level . INFO , "getSystemProperties" , ex ); // NOI18N
85
+ return call . call ();
86
+ } catch (Exception ex ) {
87
+ throw new RuntimeException ( ex );
68
88
}
69
- return null ;
89
+ }
90
+
91
+ public synchronized Properties getSystemProperties () {
92
+ return executeAndWait (() -> {
93
+ try {
94
+ return getVirtualMachine ().getSystemProperties ();
95
+ } catch (IOException ex ) {
96
+ LOGGER .log (Level .INFO ,"getSystemProperties" ,ex ); // NOI18N
97
+ }
98
+ return null ;
99
+ });
70
100
}
71
101
72
102
public synchronized boolean takeHeapDump (String fileName ) {
@@ -209,13 +239,15 @@ private synchronized Map<String,String> getVMCommandLine() {
209
239
}
210
240
211
241
private synchronized String executeJCmd (String command ) {
212
- try {
213
- InputStream in = getVirtualMachine ().executeJCmd (command );
214
- return readToEOF (in );
215
- } catch (IOException ex ) {
216
- LOGGER .log (Level .INFO ,"executeJCmd" ,ex ); // NOI18N
217
- }
218
- return null ;
242
+ return executeAndWait (() -> {
243
+ try {
244
+ InputStream in = getVirtualMachine ().executeJCmd (command );
245
+ return readToEOF (in );
246
+ } catch (IOException ex ) {
247
+ LOGGER .log (Level .INFO , "executeJCmd" , ex ); // NOI18N
248
+ }
249
+ return null ;
250
+ });
219
251
}
220
252
221
253
private String readToEOF (InputStream in ) throws IOException {
0 commit comments