Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does methods named '*Locked()' mean in Activity related classes?

I noticed that there are lots of use of the methods named '*Locked()' while I am looking through Android framework codes. I wonder what 'Locked' means and what features those methods are reflecting to.

For example, there are a number of methods named in such way in Activity related classes.

android/frameworks/base/services/java/com/android/server/am/ActivityStack.java

  • startActivityLocked()
  • ensureActivitiesVisibleLocked()
  • resumeTopActivityLocked()

Thank you for your help in advance! :)

like image 796
CodePoetry Avatar asked Oct 03 '22 19:10

CodePoetry


2 Answers

That means the method is multithread-safe.

like image 184
user3541837 Avatar answered Oct 18 '22 21:10

user3541837


You can find code from ActivityManagerService.class like below:

synchronized (this) {
    dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, null);
}

or some code like that:

synchronized (this) {
    methodA();
}
methodA() {
    dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, null);
}

So the methods named *Locked means the method is not multithread-safe, in ActivityManagerService.class, you should use synchronized (this) make sure the multithread-safe.

like image 2
DinoStray Avatar answered Oct 18 '22 21:10

DinoStray