This site requires JavaScript, please enable it in your browser!
Greenfoot back
Dallas123
Dallas123 wrote ...

2018/10/30

What does synchronized mean in this code?

Dallas123 Dallas123

2018/10/30

#
public synchronized static void initializeImages() 
    {
        if(images == null) 
        {
            GreenfootImage baseImage = new GreenfootImage("explosion-big.png");
            images = new GreenfootImage[IMAGE_COUNT];
            for (int i = 0; i < IMAGE_COUNT; i++)
            {
                int size = (i+1) * ( baseImage.getWidth() / IMAGE_COUNT );
                images[i] = new GreenfootImage(baseImage);
                images[i].scale(size, size);
            }
        }
    }
danpost danpost

2018/10/30

#
Dallas123 wrote...
What does synchronized mean in this code?
I am not really sure that synchronized needed to be used here in the Explosion class. When a method is declared to be synchronized, two or more different threads cannot simultaneously execute the method. One would be forced to wait until another has finished its execution of it. This is, however, most probably beyond the scope of what you should be concerned with at this point.
You need to login to post a reply.