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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:43:25+00:00 2026-06-14T08:43:25+00:00

for(int ii = 0; ii < 3; ii++) executor.execute(new someClass); vs someFunction(); someFunction(); someFunction();

  • 0
for(int ii = 0; ii < 3; ii++)
    executor.execute(new someClass);

vs

someFunction();
someFunction();
someFunction();

where

public static void someFunction(){
    synchronized(lock){
       for(int ii = 0; ii < long.MAX_VALUE; ii++);
    }
}


private class someClass implements Runnable {

   public void run() {          
     someFunction(); //someFunction() is  a synchronized function
   }
}

Sorry if this may be a rather vague question. I have a synchronized someFunction() that I want to call 3 times sequentially and another time with 3 threads where each one runs the task of someFunction(). Since, it is synchronized, only 1 thread can access at time, the speed difference is almost the same with 3 threads vs 1 thread. I’m also not allowed to modify or unsynchronized someFunction(). I was wondering if there is any way to speed it up the mult-threaded way from how I am using the threads? Maybe through how the threads queue or something? Thanks for any help.

  • 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-14T08:43:26+00:00Added an answer on June 14, 2026 at 8:43 am

    No. There is no way to run a synchronized method (on the same object) more than once at the same time. That is kind of the point of the synchronized keyword.

    Synchronization can become a performance bottleneck, but the only way to reduce that is to reduce the amount of work that needs to be done in those critical sections. Often code is overly conservative, and maybe not everything needs to be in that synchronized block. But this is something that requires a deep understanding and rewriting of the code, nothing that you can just tune via some magic setting (and if you remove too much synchronization, you might break things; getting multi-threaded code right is difficult).

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

Sidebar

Related Questions

public class test { public static final int nThreads = 2; public static void
public class MainClass { private static final int size = 5; private ExecutorService prodExec
public class MainClass { private static final int producerPoolSize = 10; private static final
Sample code: public class ThreadTest{ public static void main(String ...arg){ try{ ExecutorService executor =
public final void sendAdvertisement(final Advertisement advertisment, int delay, final int repetitions){ final ScheduledFuture exec
My ServletContextListener: @WebListener public class RunServlet implements ServletContextListener { private ScheduledExecutorService scheduler; @Override public
Given a Runnable object e.g. public class Test implements Runnable { @Override public void
int a = 10; int* pA = &a; long long b = 200; long
int main(void) { char testStr[50] = Hello, world!; char revS[50] = testStr; } I
int* p_bob = new int; *p_bob = 78; The above code makes sense to

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.