Lines 173-178
Link Here
|
173 |
|
173 |
|
174 |
/** support for interrupts or not? */ |
174 |
/** support for interrupts or not? */ |
175 |
private boolean interruptThread; |
175 |
private boolean interruptThread; |
|
|
176 |
/** fill stacktraces when task is posted? */ |
177 |
private boolean enableStackTraces; |
176 |
|
178 |
|
177 |
/** Creates new RequestProcessor with automatically assigned unique name. */ |
179 |
/** Creates new RequestProcessor with automatically assigned unique name. */ |
178 |
public RequestProcessor() { |
180 |
public RequestProcessor() { |
Lines 221-231
Link Here
|
221 |
* @since 6.3 |
223 |
* @since 6.3 |
222 |
*/ |
224 |
*/ |
223 |
public RequestProcessor(String name, int throughput, boolean interruptThread) { |
225 |
public RequestProcessor(String name, int throughput, boolean interruptThread) { |
|
|
226 |
this(name, throughput, interruptThread, true); |
227 |
} |
228 |
|
229 |
/** Creates a new named <code>RequestProcessor</code> that allows to disable stack trace filling. |
230 |
* By default, when assertions are on, each task posted on <code>RequestProcessor</code> stores |
231 |
* the stack trace at the time of posting. When an exception is later thrown from the task, |
232 |
* it allows to print not only stack trace of the task but also stack trace of the code that posted it. |
233 |
* However this may be a performance bottleneck in cases when hundreds of short task are scheduled. |
234 |
* This constructor then allows to create <code>RequestProcessor</code> which never stores stack traces |
235 |
* at the time of posting. |
236 |
* <p> |
237 |
* See constructor {@link #RequestProcessor(String, int, boolean)} for details of <code>interruptThread</code> |
238 |
* parameter. |
239 |
* </p> |
240 |
* @param name the name to use for the request processor thread |
241 |
* @param throughput the maximal count of requests allowed to run in parallel |
242 |
* @param interruptThread true if {@link RequestProcessor.Task#cancel} shall interrupt the thread |
243 |
* @param enableStackTraces <code>false</code> when request processor should not fill stack traces when task is posted. |
244 |
* Default is <code>true</code>. |
245 |
* @since 7.24 |
246 |
*/ |
247 |
public RequestProcessor(String name, int throughput, boolean interruptThread, boolean enableStackTraces) { |
224 |
this.throughput = throughput; |
248 |
this.throughput = throughput; |
225 |
this.name = (name != null) ? name : ("OpenIDE-request-processor-" + (counter++)); |
249 |
this.name = (name != null) ? name : ("OpenIDE-request-processor-" + (counter++)); |
226 |
this.interruptThread = interruptThread; |
250 |
this.interruptThread = interruptThread; |
|
|
251 |
this.enableStackTraces = enableStackTraces; |
227 |
} |
252 |
} |
228 |
|
253 |
|
229 |
|
254 |
|
230 |
/** The getter for the shared instance of the <CODE>RequestProcessor</CODE>. |
255 |
/** The getter for the shared instance of the <CODE>RequestProcessor</CODE>. |
231 |
* This instance is shared by anybody who |
256 |
* This instance is shared by anybody who |
Lines 627-633
Link Here
|
627 |
item.clear(null); |
652 |
item.clear(null); |
628 |
} |
653 |
} |
629 |
|
654 |
|
630 |
item = new Item(this, RequestProcessor.this); |
655 |
item = (SLOW && enableStackTraces) ? |
|
|
656 |
new SlowItem(this, RequestProcessor.this) : |
657 |
new FastItem(this, RequestProcessor.this); |
631 |
localItem = item; |
658 |
localItem = item; |
632 |
} |
659 |
} |
633 |
|
660 |
|
Lines 813-820
Link Here
|
813 |
/* One item representing the task pending in the pending queue */ |
840 |
/* One item representing the task pending in the pending queue */ |
814 |
private static class Item extends Exception { |
841 |
private static class Item extends Exception { |
815 |
private final RequestProcessor owner; |
842 |
private final RequestProcessor owner; |
816 |
private Object action; |
843 |
Object action; |
817 |
private boolean enqueued; |
844 |
boolean enqueued; |
818 |
String message; |
845 |
String message; |
819 |
|
846 |
|
820 |
Item(Task task, RequestProcessor rp) { |
847 |
Item(Task task, RequestProcessor rp) { |
Lines 849-879
Link Here
|
849 |
return getTask().getPriority(); |
876 |
return getTask().getPriority(); |
850 |
} |
877 |
} |
851 |
|
878 |
|
852 |
@Override |
|
|
853 |
public Throwable fillInStackTrace() { |
854 |
if (SLOW) { |
855 |
Throwable ret = super.fillInStackTrace(); |
856 |
StackTraceElement[] arr = ret.getStackTrace(); |
857 |
for (int i = 1; i < arr.length; i++) { |
858 |
if (arr[i].getClassName().startsWith("java.lang")) { |
859 |
continue; |
860 |
} |
861 |
if (arr[i].getClassName().startsWith(RequestProcessor.class.getName())) { |
862 |
continue; |
863 |
} |
864 |
ret.setStackTrace(Arrays.asList(arr).subList(i - 1, arr.length).toArray(new StackTraceElement[0])); |
865 |
break; |
866 |
} |
867 |
return ret; |
868 |
} else { |
869 |
return this; |
870 |
} |
871 |
} |
872 |
|
873 |
public @Override String getMessage() { |
879 |
public @Override String getMessage() { |
874 |
return message; |
880 |
return message; |
875 |
} |
881 |
} |
876 |
|
882 |
|
|
|
883 |
} |
884 |
|
885 |
private static class FastItem extends Item { |
886 |
FastItem(Task task, RequestProcessor rp) { |
887 |
super(task, rp); |
888 |
} |
889 |
|
890 |
@Override |
891 |
public Throwable fillInStackTrace() { |
892 |
return this; |
893 |
} |
894 |
} |
895 |
private static class SlowItem extends Item { |
896 |
|
897 |
SlowItem(Task task, RequestProcessor rp) { |
898 |
super(task, rp); |
899 |
} |
900 |
|
901 |
@Override |
902 |
public Throwable fillInStackTrace() { |
903 |
Throwable ret = super.fillInStackTrace(); |
904 |
StackTraceElement[] arr = ret.getStackTrace(); |
905 |
for (int i = 1; i < arr.length; i++) { |
906 |
if (arr[i].getClassName().startsWith("java.lang")) { |
907 |
continue; |
908 |
} |
909 |
if (arr[i].getClassName().startsWith(RequestProcessor.class.getName())) { |
910 |
continue; |
911 |
} |
912 |
ret.setStackTrace(Arrays.asList(arr).subList(i - 1, arr.length).toArray(new StackTraceElement[0])); |
913 |
break; |
914 |
} |
915 |
return ret; |
916 |
} |
877 |
} |
917 |
} |
878 |
|
918 |
|
879 |
//------------------------------------------------------------------------------ |
919 |
//------------------------------------------------------------------------------ |