0

I am using Spring 3.0 framework

I have a Problem regarding thread and its result. My project has many controllers and their Methods.

I have created one thread which will be called in one of the Method of Controller and i want that its result should be added in model attribute because i want to show result in JSP.

Problem is that thought i am adding thread result in model attribute bit its result is null in JSP. because use is not using currently that controller.

Examlpe :

    Spring Controller{

    //mapping
    String controllerMethod1(Model model){

    }

    //mapping
    String controllerMethod2(Model model){
      //thread will calling on this controller method
       //new myThread
      var result=new myThread.start();

      model.addattr("res",result);
    }

    //mapping
    String controllerMethod3(Model model){

    }

    //mapping
    String controllerMethod4(Model model){

    }

    //mapping
    String controllerMethod5(Model model){
    }

    }

There are many such controllers In Each return JSP page of every controller,i have ${res} to show threads return result

Please give me approriate solution and thank you.

I kow there is DefferedResult concept in Spring 3.2 But it is not in Spring 3.0. Please give me alternative solution like Deferedresult

4

2 回答 2

3

If I understand correctly, you do not want the model to contain the Thread object, you want it to contain the result computed by the thread. You need to look at the Future class. But even then, I doubt it will help you much; the JSP rendering code will want the result of the thread very soon after your controller method returns, so there will not be much time for the value to be computed. You need to reconsider why you are using threads at all.

于 2013-08-13T12:20:55.043 回答
0

I temporarily found the Solution But i want better... My Solution : I am using ExcecutorService with single thread creation.That service excecutes my threads one at a time.After completion of each thread,I am adding result in Session and after displaying session result i am removing that session attribute.

That's It!

于 2013-08-15T04:57:21.973 回答