Skip to content

Commit 0c9bea8

Browse files
unblock the user actions while running the build
1 parent 083f7af commit 0c9bea8

File tree

1 file changed

+41
-1
lines changed
  • runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs

1 file changed

+41
-1
lines changed

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/ThreadJob.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static ThreadJob joinRun(ThreadJob threadJob, IProgressMonitor monitor) {
208208
boolean interruptedDuringWaitForRun;
209209
try {
210210
// just return if lock listener decided to grant immediate access
211-
if (manager.getLockManager().aboutToWait(blocker)) {
211+
if (manager.getLockManager().aboutToWait(blocker) || identifyThreadAction()) {
212212
return threadJob;
213213
}
214214
result = waitForRun(threadJob, monitor, blockingJob);
@@ -231,6 +231,46 @@ static ThreadJob joinRun(ThreadJob threadJob, IProgressMonitor monitor) {
231231
return result;
232232
}
233233

234+
235+
public static boolean identifyThreadAction() {
236+
String threadName = Thread.currentThread().getName();
237+
Job[] jobs = Job.getJobManager().find(null);
238+
239+
// Get the job running in the current thread
240+
Job currentJob = null;
241+
for (Job job : jobs) {
242+
if (job.getThread() == Thread.currentThread()) {
243+
currentJob = job;
244+
break;
245+
}
246+
}
247+
248+
// UI Thread (User interactions)
249+
if (threadName.equals("main")) { //$NON-NLS-1$
250+
return true; // This is the UI Thread! (Handling direct user interactions)
251+
}
252+
253+
// Background Worker Threads
254+
if (threadName.contains("Worker")) { //$NON-NLS-1$
255+
if (currentJob != null) {
256+
String jobName = currentJob.getName();
257+
258+
if (jobName.toLowerCase().contains("save") || jobName.toLowerCase().contains("edit")) { //$NON-NLS-1$ //$NON-NLS-2$
259+
return true; // This thread is handling a FILE SAVE/EDIT operation.
260+
} else if (jobName.toLowerCase().contains("vcs") || jobName.toLowerCase().contains("git") //$NON-NLS-1$ //$NON-NLS-2$
261+
|| jobName.toLowerCase().contains("commit")) { //$NON-NLS-1$
262+
return true; // This thread is handling a VCS (Version Control) operation.
263+
} else if (jobName.toLowerCase().contains("build") || jobName.toLowerCase().contains("debug")) { //$NON-NLS-1$ //$NON-NLS-2$
264+
return false; // This thread is handling a BUILD/RUN/DEBUG job.
265+
} else {
266+
return false; // This thread is handling an unknown background job
267+
}
268+
}
269+
}
270+
// If not identified
271+
return false; // Thread not recognized
272+
}
273+
234274
/**
235275
* Waits until given {@code ThreadJob} "runs" (acquires the rule conflicting
236276
* with given {@code blockingJob} or is canceled. While the given

0 commit comments

Comments
 (0)