0
public static synchronized strictfp void main(String... arg)

In the above statement, can someone please explain the purpose of synchronized and strictfp for main method.

Turing85
  • 18,217
  • 7
  • 33
  • 58
user2186831
  • 355
  • 2
  • 10
  • 3
    main() method is supposed to be called by the JVM and should not be called by the programmer for internal use. Thus it should not be synchoronized – Ankur Shanbhag Jul 11 '15 at 18:47
  • As for `strictfp` you may want to take a look at [this question](http://stackoverflow.com/questions/517915/when-should-i-use-the-strictfp-keyword-in-java). Sidenote: it is a keyword, not a modifier. – Turing85 Jul 11 '15 at 18:51
  • 1
    @Turing85 - It is a modifier, see [JLS](https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.3). – RealSkeptic Jul 11 '15 at 19:05
  • I don't think the `synchronized` modifier has a purpose, but it does have an effect - no thread will be able to synchronize on the class monitor for the life of the program (unless the main thread yields it by calling `wait()`). – RealSkeptic Jul 11 '15 at 19:08

1 Answers1

0

Few good explanation for java synchronized is given here - what-does-synchronized-mean and learning-java-use-of-synchronized-keyword

Now, if main method is synchronized, only one thread can enter into this method, which is the java main thread (assuming that the class is executed as main class).

For executing this method, the main thread will acquire the class level lock (being a static method). So, if the class is having more static synchronized methods, those will be blocked forever for other thread, until main thread completes the execution or go into wait state.

strictfp is Java is explained when-should-i-use-the-strictfp-keyword-in-java and strictfp-in-java

It does not have any different behavior with main().

Community
  • 1
  • 1
Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53