Package hudson.model

Class Executor

java.lang.Object
java.lang.Thread
hudson.model.Executor
All Implemented Interfaces:
ModelObject, Runnable
Direct Known Subclasses:
OneOffExecutor

@ExportedBean public class Executor extends Thread implements ModelObject
Thread that executes builds. Since 1.536, Executors start threads on-demand.

Callers should use isActive() instead of Thread.isAlive().

Author:
Kohsuke Kawaguchi
  • Field Details

    • owner

      @NonNull protected final Computer owner
  • Constructor Details

    • Executor

      public Executor(@NonNull Computer owner, int n)
  • Method Details

    • interrupt

      public void interrupt()
      Overrides:
      interrupt in class Thread
    • interrupt

      public void interrupt(Result result)
      Interrupt the execution, but instead of marking the build as aborted, mark it as specified result.
      Since:
      1.417
    • interrupt

      public void interrupt(Result result, CauseOfInterruption... causes)
      Interrupt the execution. Mark the cause and the status accordingly.
    • abortResult

      public Result abortResult()
    • recordCauseOfInterruption

      public void recordCauseOfInterruption(Run<?,?> build, TaskListener listener)
      report cause of interruption and record it to the build, if available.
      Since:
      1.425
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • completedAsynchronous

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void completedAsynchronous(@CheckForNull Throwable error)
    • getCurrentExecutable

      @CheckForNull public Queue.Executable getCurrentExecutable()
      Returns the current build this executor is running.
      Returns:
      null if the executor is idle.
    • getCurrentExecutableForApi

      @Exported(name="currentExecutable") @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public Queue.Executable getCurrentExecutableForApi()
      Same as getCurrentExecutable() but checks Item.READ.
    • getCausesOfInterruption

      @NonNull public Collection<CauseOfInterruption> getCausesOfInterruption()
      Returns causes of interruption.
      Returns:
      Unmodifiable collection of causes of interruption.
      Since:
      1.617
    • getCurrentWorkUnit

      @CheckForNull public WorkUnit getCurrentWorkUnit()
      Returns the current WorkUnit (of the current executable) that this executor is running.
      Returns:
      null if the executor is idle.
    • getCurrentWorkspace

      public FilePath getCurrentWorkspace()
      If current executable is AbstractBuild, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.
    • getDisplayName

      public String getDisplayName()
      Human readable name of the Jenkins executor. For the Java thread name use Thread.getName().
      Specified by:
      getDisplayName in interface ModelObject
    • getNumber

      @Exported public int getNumber()
      Gets the executor number that uniquely identifies it among other Executors for the same computer.
      Returns:
      a sequential number starting from 0.
    • isIdle

      @Exported public boolean isIdle()
      Returns true if this Executor is ready for action.
    • isBusy

      public boolean isBusy()
      The opposite of isIdle() — the executor is doing some work.
    • isActive

      public boolean isActive()
      Check if executor is ready to accept tasks. This method becomes the critical one since 1.536, which introduces the on-demand creation of executor threads. Callers should use this method instead of Thread.isAlive(), which would be incorrect for non-started threads or running AsynchronousExecution.
      Returns:
      true if the executor is available for tasks (usually true)
      Since:
      1.536
    • getAsynchronousExecution

      @CheckForNull public AsynchronousExecution getAsynchronousExecution()
      If currently running in asynchronous mode, returns that handle.
      Since:
      1.607
    • isDisplayCell

      public boolean isDisplayCell()
      If this executor is running an AsynchronousExecution and that execution wants to hide the display cell for the executor (because there is another executor displaying the job progress and we don't want to confuse the user) then this method will return false to indicate to executors.jelly that the executor cell should be hidden.
      Returns:
      true iff the executorCell.jelly for this Executor should be displayed in executors.jelly.
      Since:
      1.607
      See Also:
    • isParking

      public boolean isParking()
      Returns true if this executor is waiting for a task to execute.
    • getCauseOfDeath

      @Deprecated @CheckForNull public Throwable getCauseOfDeath()
      Deprecated.
      no longer used
    • getProgress

      @Exported public int getProgress()
      Returns the progress of the current build in the number between 0-100.
      Returns:
      -1 if it's impossible to estimate the progress.
    • isLikelyStuck

      @Exported public boolean isLikelyStuck()
      Returns true if the current build is likely stuck.

      This is a heuristics based approach, but if the build is suspiciously taking for a long time, this method returns true.

    • getElapsedTime

      public long getElapsedTime()
    • getTimeSpentInQueue

      public long getTimeSpentInQueue()
      Returns the number of milli-seconds the currently executing job spent in the queue waiting for an available executor. This excludes the quiet period time of the job.
      Since:
      1.440
    • getTimestampString

      public String getTimestampString()
      Gets the string that says how long since this build has started.
      Returns:
      string like "3 minutes" "1 day" etc.
    • getEstimatedRemainingTime

      public String getEstimatedRemainingTime()
      Computes a human-readable text that shows the expected remaining time until the build completes.
    • getEstimatedRemainingTimeMillis

      public long getEstimatedRemainingTimeMillis()
      The same as getEstimatedRemainingTime() but return it as a number of milli-seconds.
    • start

      public void start()
      Can't start executor like you normally start a thread.
      Overrides:
      start in class Thread
      See Also:
      • start(WorkUnit)
    • doStop

      @Deprecated public void doStop(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
      Deprecated.
      as of 1.489 Use doStop() or doStopBuild(String).
      Throws:
      IOException
      javax.servlet.ServletException
    • doStop

      public org.kohsuke.stapler.HttpResponse doStop()
      Stops the current build.
      You can use doStopBuild(String) instead to ensure what will be interrupted is actually what you want to interrupt.
      Since:
      1.489
      See Also:
    • doStopBuild

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public org.kohsuke.stapler.HttpResponse doStopBuild(@CheckForNull @QueryParameter(fixEmpty=true) String runExtId)
      Stops the current build, if matching the specified external id (or no id is specified, or the current Queue.Executable is not a Run).
      Parameters:
      runExtId - if not null, the externalizable id (Run.getExternalizableId()) of the build the user expects to interrupt
      Since:
      2.209
    • doYank

      @Deprecated public org.kohsuke.stapler.HttpResponse doYank()
      Deprecated.
      now a no-op
    • hasStopPermission

      public boolean hasStopPermission()
      Checks if the current user has a permission to stop this build.
    • getOwner

      @NonNull public Computer getOwner()
    • getIdleStartMilliseconds

      public long getIdleStartMilliseconds()
      Returns when this executor started or should start being idle.
    • getApi

      public Api getApi()
      Exposes the executor to the remote API.
    • newImpersonatingProxy

      public <T> T newImpersonatingProxy(Class<T> type, T core)
      Creates a proxy object that executes the callee in the context that impersonates this executor. Useful to export an object to a remote channel.
    • currentExecutor

      @CheckForNull public static Executor currentExecutor()
      Returns the executor of the current thread or null if current thread is not an executor.
    • of

      @CheckForNull public static Executor of(Queue.Executable executable)
      Finds the executor currently running a given process.
      Parameters:
      executable - a possibly running executable
      Returns:
      the executor (possibly a OneOffExecutor) whose getCurrentExecutable() matches that, or null if it could not be found (for example because the execution has already completed)
      Since:
      1.607
    • getEstimatedDurationFor

      @Deprecated public static long getEstimatedDurationFor(Queue.Executable e)
      Deprecated.