Skip to content

Instantly share code, notes, and snippets.

@yazinnnn

yazinnnn/java Secret

Created September 20, 2023 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yazinnnn/92a90ddb81579fdc619ca14395bf3dc2 to your computer and use it in GitHub Desktop.
Save yazinnnn/92a90ddb81579fdc619ca14395bf3dc2 to your computer and use it in GitHub Desktop.
import io.smallrye.common.annotation.RunOnVirtualThread;
import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.time.Duration;
@Path("/hello")
public class GreetingResource {
@GET
@Path("virtual")
@Produces(MediaType.TEXT_PLAIN)
@RunOnVirtualThread
public String hello1() {
return "Hello from virtual thread";
}
@GET
@Path("reactive")
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> hello2() {
return Uni.createFrom().item("Hello from reactive");
}
@GET
@Path("virtual-delay")
@Produces(MediaType.TEXT_PLAIN)
@RunOnVirtualThread
public String hello3() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return "Hello from virtual thread delay";
}
@GET
@Path("reactive-delay")
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> hello4() {
return Uni.createFrom().item("Hello from reactive delay")
.onItem().delayIt().by(Duration.ofMillis(100));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment