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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:37:06+00:00 2026-06-07T22:37:06+00:00

please look at this class, static method calls and output. public class OneThreadManyStaticCalls {

  • 0

please look at this class, static method calls and output.

public class OneThreadManyStaticCalls {

public static final Calculator calculator = new Calculator();
    public static void main(String[] args) {
        dummy(0, 1, 1);
        dummy(0, 2, 2);
        dummy(0, 3, 5);
        dummy(0, 4, 44);
        dummy(0, 5, 5);
    }

    public static void dummy(int a, int b, int expected) {

        System.out.print(System.currentTimeMillis() + "\t");
        if (calculator.add(a, b) == expected) {
            System.out.println("OK");
        } else {
            System.err.println("NOK");
        }
    }
}

I got diffrent (order from System.out.print) ouputs running this program. Example:

   NOK
   NOK
   1342527389506    OK
   1342527389506    OK
   1342527389506    1342527389506   1342527389506   OK

Could any of you explain me (with details) why?
Thanks in advance.
sznury

  • 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-07T22:37:08+00:00Added an answer on June 7, 2026 at 10:37 pm

    System.err and System.out are two different streams which are interleaved in your console window – they’re not necessarily synchronized. Try using System.*.flush() (nevermind, this doesn’t seem to work) to force the output to be handled, or print all your output to the same stream.

    public static void dummy(int a, int b, int expected) {
        System.out.print(System.currentTimeMillis() + "\t");
        if ((a + b) == expected) { // I don't have your Calculator :<
            System.out.println("OK");
        } else {
            System.out.println("NOK");
        }
    }
    

    Gives this result

    1342528255764   OK
    1342528255764   OK
    1342528255764   NOK
    1342528255764   NOK
    1342528255764   OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at this code please: #include <iostream> using namespace std; class Ratio { public:
Please,look at this simple class: class TernaryPolynomial; class IntegerPolynomial; class DenseTernaryPolynomial:public IntegerPolynomial,public TernaryPolynomial {
Please, take a look at this example: import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Test
Please look at my sourcecode. public class EntityQuery { public static Func<AdventureWork2008Container, IQueryable<SalesPerson>> selectQuery
THis is myDB Class //Please take a look at public Cursor getplaces() --- Am
Please take a look at this code: template<class T> class A { class base
Please look at this code: @interface myObject:NSObject -(void)function:(id)param; @end @implementation myObject -(void)function:(id)param { NSLog(@BEFORE);
I have the following extension method public static class ListExtensions { public static IEnumerable<T>
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
I have a method like this public static DataSet GetAllDataBaseNames() { //Instance of connection

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.