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 171877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:03:57+00:00 2026-05-11T13:03:57+00:00

I am asking this purely to determine the worthwhile-ness of implementing the class in

  • 0

I am asking this purely to determine the worthwhile-ness of implementing the class in Question …

Do you know of a Java utility class that takes an un-synchronized instance, uses reflection to investigate that instance, and returns the input instance ‘wrapped’ within synchronized calls ?

( ie: A factory which creates a synchronized delegate class for any instance )

  • 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. 2026-05-11T13:03:57+00:00Added an answer on May 11, 2026 at 1:03 pm

    I like Jon Skeet’s answer; it’s seeing the forest instead of the trees. But to answer the question:

    Assuming that the instance belongs to some interface, it’s easy to use java.lang.reflect.Proxy to do this.

    public final class SynchronizedFactory {     private SynchronizedFactory() {}      public static <T> T makeSynchronized(Class<T> ifCls, T object) {         return ifCls.cast(Proxy.newProxyInstance(                 object.getClass().getClassLoader(),                 new Class<?>[] {ifCls},                 new Handler<T>(object)));     }      private static class Handler<T> implements InvocationHandler {         private final T object;          Handler(T object) {             this.object = object;         }          @Override         public Object invoke(Object proxy, Method method,                 Object[] args) throws Throwable {             synchronized (object) {                 return method.invoke(object, args);             }         }     } } 

    This code is not tested, by the way. Use at your own risk.

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

Sidebar

Related Questions

The very act of asking this question suggests that my approach to this problem
I'm asking this question purely from an ease-of-development standpoint. Performance is not a consideration,
After asking this question about implementing an aspect with PostSharp, it came to my
After asking this question I realized that to build what I need I'd better
I'm asking this question purely from a usability standpoint ! Should a website expand/stretch
While asking this question , I realized I didn't know much about raw strings.
I am asking this question here because it is my understanding that this is
Asking this question because I feel that member variables of my base will be
I already tried asking this question at Relative layout Coding , but that first
I'm asking this because I know that the pythonic way to check whether a

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.