samedi 28 février 2015

Why Tomcat's LifyCycleSupport.java use array to store listeners instead of any advanced containers(ArrayList)?


Vote count:

0




Im recently going through tomcat's source code, I found that in the LifecycleSupport.java class, it stores Listeners by simple arrays,



private LifecycleListener listeners[] = new LifecycleListener[0];


so the add() method has to create a new array to replace the old one:



public void addLifecycleListener(LifecycleListener listener) {
82
83 synchronized (listenersLock) {
84 LifecycleListener results[] =
85 new LifecycleListener[listeners.length + 1];
86 for (int i = 0; i < listeners.length; i++)
87 results[i] = listeners[i];
88 results[listeners.length] = listener;
89 listeners = results;
90 }
91
92 }


I wonder whats the purpose to use array instead of advanced java containers like ArrayList, since its much more convenient to perform add/remove action?


Thanks



asked 34 secs ago

Qing

100






Why Tomcat's LifyCycleSupport.java use array to store listeners instead of any advanced containers(ArrayList)?

Aucun commentaire:

Enregistrer un commentaire