Package hudson.model

Class Executor

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

@ExportedBean public class Executor extends Thread implements ModelObject, IExecutor
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.
      Specified by:
      getCurrentExecutable in interface IExecutor
      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()
      Description copied from interface: IExecutor
      Returns the current WorkUnit (of the current executable) that this executor is running.
      Specified by:
      getCurrentWorkUnit in interface IExecutor
      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 IExecutor
      Specified by:
      getDisplayName in interface ModelObject
      Returns:
      the current display name of the executor. Usually the name of the executable.
    • getNumber

      @Exported public int getNumber()
      Description copied from interface: IExecutor
      Gets the executor number that uniquely identifies it among other IExecutors for the same computer.
      Specified by:
      getNumber in interface IExecutor
      Returns:
      a sequential number starting from 0.
    • isIdle

      @Exported public boolean isIdle()
      Description copied from interface: IExecutor
      Returns true if this IExecutor is ready for action.
      Specified by:
      isIdle in interface IExecutor
    • 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()
      Description copied from interface: IExecutor
      Returns the progress of the current build in the number between 0-100.
      Specified by:
      getProgress in interface IExecutor
      Returns:
      -1 if it's impossible to estimate the progress.
    • isLikelyStuck

      @Exported public boolean isLikelyStuck()
      Description copied from interface: IExecutor
      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.

      Specified by:
      isLikelyStuck in interface IExecutor
    • getElapsedTime

      public long getElapsedTime()
      Description copied from interface: IExecutor
      Gets the elapsed time since the build has started.
      Specified by:
      getElapsedTime in interface IExecutor
      Returns:
      the number of milliseconds since the build has started.
    • 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
    • getEstimatedRemainingTime

      public String getEstimatedRemainingTime()
      Description copied from interface: IExecutor
      Computes a human-readable text that shows the expected remaining time until the build completes.
      Specified by:
      getEstimatedRemainingTime in interface IExecutor
    • 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()
      Description copied from interface: IExecutor
      Checks if the current user has a permission to stop this build.
      Specified by:
      hasStopPermission in interface IExecutor
    • getOwner

      @NonNull public Computer getOwner()
      Specified by:
      getOwner in interface IExecutor
      Returns:
      the IComputer that this executor belongs to.
    • 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.