正在加载图片...
5.4.1 Concept of Monitors(6/10) It is simple to turn a java class into a monitor Make all the data private Make all methods synchronized or at least the non private ones) class Queuet private…;∥/ queue data public void synchronized Add( object item t put item on queue public object synchronized removed i if queue not empty i remove item return item5.4.1 Concept of Monitors(6/10) • It is simple to turn a Java class into a monitor: • Make all the data private • Make all methods synchronized (or at least the non - private ones) 11 class Queue{ private ...; // queue data public void synchronized Add( Object item ) { put item on queue; } public Object synchronized Remove() { if queue not empty { remove item; return item; } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有