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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:55:45+00:00 2026-06-12T16:55:45+00:00

I was reading a thread from CodeRanch saying that abstract methods could not be

  • 0

I was reading a thread from CodeRanch saying that abstract methods could not be synchronized due to the fact that an abstract class cannot be instantiated, meaning no object to lock.

This doesn’t make sense since an abstract class is a definition (contract) for a child class. The abstract definition of a synchronized method does not need to lock, the child does. All the abstract heading would indicate is that the child must synchronize this method. Is my logic on this correct? If not can someone explain why I’m wrong?

  • 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-06-12T16:55:46+00:00Added an answer on June 12, 2026 at 4:55 pm

    The comment about not being able to instantiate the abstract class is garbage. Given that it has to be an instance method to be abstract, there certainly is a reference which could be locked on. Concrete methods in abstract classes can still refer to this. However, that still doesn’t mean that abstract classes should be able to be synchronized.

    Whether or not a method is synchronized is an implementation detail of the method. Synchronization isn’t specified anywhere as a declarative contract – it’s not like you can synchronize in interfaces, either.

    How a class implements whatever thread safety guarantees it provides is up to it. If an abstract class wants to mandate a particular approach, it should use the template method pattern:

    // I hate synchronizing on "this"
    private final Object lock = new Object();
    
    public final void foo() {
        synchronized(lock) {
            fooImpl();
        }
    }
    
    protected abstract void fooImpl();
    

    That’s pretty dangerous in itself though, given that it’s effectively calling “unknown” code within a lock, which is a recipe for deadlocks etc.

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

Sidebar

Related Questions

I remember reading that static variables declared inside methods is not thread-safe. (See What
Could I close tcp::socket in different thread from the sync-reading thread? It looks like:
I have a thread reading data from a bluetooth stream that sends the data
Are there any concurrency problems with one thread reading from one index of an
It's clear from reading through threads that I can call a PHP function using
It's my understanding that if two threads are reading from the same piece of
I am little confused... Is it true that reading\writing from several threads all except
Basically I have a thread reading from c++ std::istream using istream& getline ( istream&
I'm trying to use the Win32 API to make a sub-thread that reads from
I'm currently reading a java concurrency tutorial in http://tutorials.jenkov.com/java-concurrency/creating-and-starting-threads.html I could not understand what

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.