Parsing @Context UriInfo to java thread

谁说我不能喝 提交于 2020-01-11 07:49:06

问题


I'm trying to parse @Context UriInfo to another thread and do some task. But when i try to run it, it gives the error as

Exception in thread "Thread-691" org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data of type: javax.ws.rs.core.UriInfo

My code as follows

@GET
@Path("/thread")

public void thread(@Context UriInfo url){


Runnable run = new Runnable() {
    @Override
    public void run() {
        System.out.println(">>>>>>>>>>>> " + url.getRequestUri().getQuery());
    }
};

Thread t = new Thread(run);

t.start();

}

How can I get the UriInfo to the new thread?


回答1:


Just make the UriInfo parameter final and you will be able to access it from your run() method.

public void thread(@Context final UriInfo url){

I've no idea what you are actually trying to achieve here though. I doubt you actually want to do this.



来源:https://stackoverflow.com/questions/42649287/parsing-context-uriinfo-to-java-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!