Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:14:33+00:00 2026-05-31T11:14:33+00:00

Following code create that Annotation. As described here, http://engineering.webengage.com/2012/03/12/a-peek-into-webengages-security-layer-super-cool-use-of-java-annotations /** * Defining the Asynch

  • 0

Following code create that Annotation.

As described here,
http://engineering.webengage.com/2012/03/12/a-peek-into-webengages-security-layer-super-cool-use-of-java-annotations

/**
 * Defining the Asynch interface
 */
@Retention(RetentionPolicy.RUNTIME)
public @interface Asynch {}

/**
 * Implementation of the Asynch interface. Every method in our controllers
 * goes through this interceptor. If the Asynch annotation is present,
 * this implementation invokes a new Thread to execute the method. Simple!
 */
public class AsynchInterceptor implements MethodInterceptor {
  public Object invoke(final MethodInvocation invocation) throws Throwable {
    Method method = invocation.getMethod();
    Annotation[] declaredAnnotations = method.getDeclaredAnnotations(); 
    if(declaredAnnotations != null && declaredAnnotations.length > 0) {
      for (Annotation annotation : declaredAnnotations) {
        if(annotation instanceof Asynch) {
          //start the requested task in a new thread and immediately
          //return back control to the caller
          new Thread(invocation.getMethod().getName()) {
            public void execute() {
              invocation.proceed();
            }
          }.start();
          return null;
        }
      }
    }
    return invocation.proceed();
  }
}

And it is used with method calls that returns nothing ( void ).

Example,

/**
 * So, earlier we had a simple method in our interface which we later
 * annotated with the Asynch @interface. Bang! The caller doesn't need
 * to worry about it now. This method (no matter who the caller is)
 * gets executed asynchronously. Ain't that awesome? 
 */
@Asynch
public void refreshSurveyStatusOnResponse(String licenseCode, Integer surveyId);

What are the pros and cons ? What if we used a message queue and worker thread pool to solve instead of asynchronous method call ?
What solution could have been used from standard java instead of such homegrown solution?
Above method seems to have one backlog that Asynch method calls do not return any value in such a case above code will break. ,Is it logical to expect a return value on asynchronous method call ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:14:35+00:00Added an answer on May 31, 2026 at 11:14 am

    What are the pros and cons ?

    You should be able to work out the pros. If you can’t think of any; you have a solution looking for a problem to solve. Usually the idea is to improve the performance of the thread which is not waiting for the result of the call.

    Cons, if you are not careful it could be slower instead of faster. Depends on the voerhead vs the time saved.

    What if we used a message queue and worker thread pool to solve instead of asynchronous method call ?

    The only way to know is to try it.

    What solution could have been used from standard Java instead of such homegrown solution?

    You can use an ExecutoreService which returns a Future object. You can get the result or exception with get()

    Above method seems to have one backlog that Asynch method calls do not return any value in such a case above code will break. ,Is it logical to expect a return value on asynchronous method call ?

    ExecutorServices return a Future which can have a return value or the Exception/Throwable which is a thrown (another possible result 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I create a function for following code so that i may not
I have the following code, that in my head should create a new row
Lets say that I'm trying to create a new process with the following code:
I have a JScrollPane that holds a JLabel using the following code: //Create TEXT
I have the following code that creates a serverside object of the xmlhttp class.
I have the following code that creates the meta-description. I'm getting a 0 as
I have the following code that creates a submenu based on current document. The
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I use following code: Create a retry policy, when error, retry after 1 second,
i wrote following code to create a linkbutton programmatically, but its showing like lable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.