-
-
Save yazinnnn/92a90ddb81579fdc619ca14395bf3dc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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