All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hm.binkley.lombok.ThreadNamed Maven / Gradle / Ivy

There is a newer version: 6
Show newest version
package hm.binkley.lombok;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Formatter;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.SOURCE;

/**
 * {@code ThreadNamed} sets the thread name during method or constructor
 * execution, restoring it when the method or constructor completes (normally or
 * exceptionally).
 *
 * @author B. K. Oxley (binkley)
 * @todo Eclipse handler
 */
@Documented
@Retention(SOURCE)
@Target({CONSTRUCTOR, METHOD})
public @interface ThreadNamed {
    /**
     * The name for the thread while the annotated method or constructor
     * executes.  {@code value} is treated as a formatted string for {@link
     * String#format(String, Object...)} with any method or constructor
     * parameters passed in as formatting args.  Use positional
     * notation to skip parameters, or they may be ignroed entirely in
     * which case {@code value} is treated as a plain string.
     * 

* Example with formatting:

     * &64;ThreadNamed("Foo #%2$s")
     * public void doFoo(final String name, final int slot, final Object data) {
     *     // Do something interesting with method parameters
     * }
when called with {@code "apple", 2, 3.14159} will set the current * thread name to * "Foo #2" while {@code doFoo} executes. * * @see Formatter */ String value(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy