Skip to content

Annotations support

Egor Ushakov edited this page Jul 2, 2018 · 6 revisions

Async Annotations

In IDEA 2018.1 you can use code annotations to setup instrumenting agent for debugger Async Stack Traces. Add dependency on the updated jetbrains annotations (Maven Central) and use @Async.Schedule and @Async.Execute in your code.

Source code of the Async annotations is in this repository.

Debug the example:

import org.jetbrains.annotations.Async;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class AsyncSchedulerExample {
    private static final BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            try {
                while (true) {
                    process(queue.take());
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        schedule(1);
        schedule(2);
        schedule(3);
    }

    private static void schedule(@Async.Schedule Integer i) throws InterruptedException {
        System.out.println("Scheduling " + i);
        queue.put(i);
    }

    private static void process(@Async.Execute Integer i) {
        // Put a breakpoint here
        System.out.println("Processing " + i);
    }
}
Clone this wiki locally