将@Context UriInfo解析为java线程 [英] Parsing @Context UriInfo to java thread

查看:168
本文介绍了将@Context UriInfo解析为java线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 @Context UriInfo 解析为另一个线程并执行一些任务。但是当我尝试运行它时,它会给出错误

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

我的代码如下

@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();

}

我怎样才能获得UriInfo到新线程?

How can I get the UriInfo to the new thread?

推荐答案

只需将UriInfo参数设为最终,您就可以从run()方法访问它。

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.

这篇关于将@Context UriInfo解析为java线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆