Concurrency Control with Java and Relational Databases
java并发之如何解决线程安全问题

java并发之如何解决线程安全问题并发(concurrency)⼀个并不陌⽣的词,简单来说,就是cpu在同⼀时刻执⾏多个任务。
⽽Java并发则由多线程实现的。
在jvm的世界⾥,线程就像不相⼲的平⾏空间,串⾏在虚拟机中。
(当然这是⽐较笼统的说法,线程之间是可以交互的,他们也不⼀定是串⾏。
)多线程的存在就是压榨cpu,提⾼程序性能,还能减少⼀定的设计复杂度(⽤现实的时间思维设计程序)。
这么说来似乎线程就是传说中的银弹了,可事实告诉我们真正的银弹并不存在。
多线程会引出很多难以避免的问题,如死锁,脏数据,线程管理的额外开销,等等。
更⼤⼤增加了程序设计的复杂度。
但他的优点依旧不可替代。
死锁和脏数据就是典型的线程安全问题。
简单来说,线程安全就是:在多线程环境中,能永远保证程序的正确性。
只有存在共享数据时才需要考虑线程安全问题。
java内存区域:其中,⽅法区和堆就是主要的线程共享区域。
那么就是说共享对象只可能是类的属性域或静态域。
了解了线程安全问题的⼀些基本概念后,我们就来说说如何解决线程安全问题。
我们来从⼀个简单的servlet⽰例来分析:public class ReqCounterServlet extends HttpServlet{private int count = 0;public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {count++;System.out.print("当前已达到的请求数为" + count);}public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {// ignore}}1. 了解业务场景的线程模型这⾥的线程模型指的是: 在该业务场景下,可能出现的线程调⽤实况。
同时控制的名词解释

同时控制的名词解释同时控制(concurrent control),指在多任务系统中,通过合理的调度算法和资源管理,使得多个任务可以并发地执行,从而提高系统的效率和吞吐量。
同时控制是操作系统领域中的重要概念,它涉及到任务调度和资源管理等方面,它确保了多个任务之间的正确交互和共享资源的安全性。
在传统的单处理器系统中,只能同时执行一个任务,即一次只能执行一个程序。
而在多任务系统中,可以同时执行多个任务,即一次可以执行多个程序。
这就需要使用同时控制的技术来管理和调度这些任务,以便它们能够在合理的时间内得到有效的执行。
同时控制主要包括两个方面:任务调度和资源管理。
任务调度是指如何合理地分配和调度任务,以满足任务的执行要求和系统的性能要求。
资源管理是指如何管理和分配系统资源,如处理器、内存、IO设备等,以保证多个任务能够共享和使用这些资源。
在同时控制中,任务调度是一个重要的环节。
任务调度决定了每个任务在多任务系统中的执行顺序和运行时间。
常见的任务调度算法包括先来先服务调度(FCFS)、最短作业优先调度(SJF)、轮转调度(RR)等。
这些调度算法根据任务的特点和系统的需求,选择不同的方式来安排任务的执行。
同时控制中的另一个重要方面是资源管理。
资源管理主要涉及到共享资源的安全性和争用问题。
多个任务对共享资源的访问可能会发生冲突,导致资源使用的不一致性和错误。
同时控制通过使用互斥、同步和通信等技术手段,来保护共享资源的访问安全,并确保任务之间的正确交互。
在同时控制中,还存在一些特殊的问题和挑战。
例如,死锁问题是指当多个任务互相等待对方占用的资源,导致所有任务都无法继续执行时所产生的一种现象。
解决死锁问题需要采用合理的资源分配策略和预防措施,以避免死锁的发生。
另外,优先级反转问题是指低优先级任务占用了高优先级任务所需的资源,导致系统性能下降或任务无法按时完成。
解决优先级反转问题需要合理设置任务的优先级和使用优先级继承技术等手段。
java concurrentmap详解

文章标题:深度剖析Java ConcurrentMap:高效并发操作的利器【导语】在当今信息爆炸的时代,高效并发操作成为了软件开发中的一大挑战。
而Java语言的ConcurrentMap作为高效并发操作的利器,其强大的功能和性能优势备受开发者青睐。
本文将深度剖析Java ConcurrentMap的原理、使用方法和优缺点,带你领略并发编程的魅力。
一、理论基础在并发编程中,线程安全是一个必须被认真对待的问题。
而ConcurrentMap作为Java中线程安全的Map实现,能够保证多线程并发访问时的数据一致性和操作的原子性。
它基于分段锁的机制,将数据分成多个片段,不同的线程可以同时访问不同的片段,从而提高了并发访问的效率。
与传统的HashMap相比,ConcurrentMap能够有效减少锁的竞争,提供更好的性能。
二、使用方法在实际应用中,我们可以通过ConcurrentMap接口的实现类ConcurrentHashMap来进行并发操作。
它提供了丰富的API接口,可以满足多种并发场景下的需求。
put、get、remove等基本操作,以及size、isEmpty等元数据操作。
ConcurrentHashMap还提供了诸如keySet、values、entrySet等视图操作,方便我们对Map进行遍历和操作。
三、性能优势ConcurrentMap在多线程并发访问时能够保持较高的性能。
这得益于它采用了分段锁的机制,不同的线程可以同时操作不同的片段,从而减少了锁的竞争,提高了并发访问的效率。
在元素数量比较大的情况下,ConcurrentMap能够自动扩容,保证操作的高效性。
四、局限性虽然ConcurrentMap在多线程并发访问中有着明显的优势,但也存在一些局限性。
ConcurrentMap并不能保证所有操作的原子性,如putIfAbsent和remove等操作并不是原子性的。
对于一些复合操作,需要我们手动加锁来保证操作的原子性和一致性。
Cooperative Concurrency Control

Institut für Mathematische Maschinenund Datenverarbeitungder Friedrich-Alexander-UniversitätErlangen-Nürnberg Lehrstuhl für Informatik IV(Betriebssysteme)Cooperative Concurrency ControlRainer PruyUniversity Erlangen-NürnbergInstitut für mathematische Maschinen und Datenverarbeitung IVLehrstuhl für BetriebssystemeMartensstraße 1D-W-8520ErlangenGermanyphone: +499131 85-7909fax: +49913139388email: pruy@informatik.uni-erlangen.deAbstractToday research on concurrency in object systems concentrates on concurrent objects. If onehas to address situations involving concurrency control conditions spanning several objects one isstill on one’s own. This paper illustrates the need to be able to describe concurrency control in distri-buted situations. It presents the concept of cooperative concurrency control as a first step in addres-sing this problem. Cooperative concurrency control separates functional behaviour and concurrency control into individual objects interacting to achieve the behaviour of a single concurrent object. Asthis approach is based on object interaction it naturally extends to distributed situations.Keywordsconcurrency, distribution, object interaction, cooperation, composition1§1IntroductionExperience has taught that integrating concurrency with the notion of objects is not an easy task. Research in this field focused on the problem of concurrent objects. The main reason behind this is the observation that the need for concurrency control is evident only at the level of individual objects.An important concept of object systems is encapsulation. It prevents the implementation of an object from being visible and accessible from outside that object. Instead the behaviour of an object is specified in a more abstract description called interface. This provides for independen-ce of the clients of an object from the actual implementation.In a sequential context the interface needs only to describe the functional aspects of the beha-viour of an object. In the presence of concurrency, the interface, in addition to this functional aspect, has to reflect dynamic behaviour. In recent ongoing approaches objects are assumed to be concurrent and dynamic behaviour is specified in terms of concurrency constraints applied to method invocations ([Caro90],[Geib92],[Frøl92]).Inheritance, according to [Wegn87], is the defining property of object orientation. It formalizes incremental modifications as a key means to achieving reuse. Recent works (e. g. [BeAk92],[-Mats90], [Shiba91]) concentrated on integrating concurrency control with inheritance. The re-sults can be summarized by the following two requirements for object interface descriptions:–separation of concernsThe different aspects of the behaviour of an object should be specified using sepa-rate descriptions allowing for independent modifications of these descriptions. Inthe presence of concurrency there are at least two such aspects, namely functionalbehaviour and dynamic behaviour. If there are independent aspects of dynamic be-haviour even these should be expressed using separate descriptions.The overall behaviour of an object results from a combination of all behaviouralaspects. Incremental modification of individual aspects requires clean interfacesbetween the separate descriptions.–flexible modelling of an object-state needed for concurrency controlEncapsulation prevents concurrency constraints from referring to state informationinternal to the object. Thus, needed state information has to be modelled at the in-terface level. The limitations of the underlying principles used in this modellingprocess restrict the set of concurrency constraints, which can be expressed.The aforementioned approaches concentrate on concurrency within a single object. Later in this paper it is stated that handling concurrency internal to objects is not sufficient. Currently there are no approaches addressing concurrency problems involving several objects. [Holl92] and [John91] among others propose concepts to specify multi-object configurations. However, they concentrate on functional aspects of object composition. They do not account for additional concurrency constraints arising from such composition. Section 2 will discuss distributed con-2§ 2Concurrency in distributed environmentscurrency and the solutions available with current object systems. A model for concurrency con-trol will be presented in section 3. Based on this model an implementation strategy is developed, which is outlined in section 4.2Concurrency in distributed environmentsObjects provide a natural way for expressing distribution. They already describe a distributed system. In this system the processing of methods models local operations and object interaction models the communication among (distributed) components. By packaging objects during the process of configuring a system, coarser distributional situations can be reflected. Handling con-currency only in the (local) context of individual objects ignores the need for controlling con-current execution under constraints spanning several objects.A standard answer to this problem is delegating responsibility to alternate concepts. Usually tr-ansaction concepts are mentioned. However, transactions are not well suited for handling gene-ral concurrency control problems. They are intended for achieving data consistency and use the concept of mutual exclusion to achieve this goal. If concurrency constraints include flow control or operation sequence requirements, transactions do not aid in formulating a solution.An alternate approach to handling concurrency control in distributed situations is to introduce a central object which manages concurrency constraints. Such an object requires only object in-ternal concurrency control mechanisms. Therefore this approach can be followed with available object systems. It voids, however, any possibility of exploiting distribution. For example, it is no longer possible to optimize placement of objects within a system for communication costs as any access to the objects involved in a distributed concurrent constellation has to get through this central concurrency control object. A simple example will illustrate the problem.In an object environment it is easy to construct a buffer with a FIFO behaviour based on object references. This allows objects which are currently elements of that buffer to remain at their lo-cation within the object system. Figure 2.1 pictures a linked list implementation of such a buffer. Usually the behaviour of such a buffer would be implemented using a single object. It would probably use two instance variables, in the example called fifo_head and fifo_tail, for managing the linked list of elements. Now, if the programmer knows that retrieve always gets called from a certain point within the system and store always gets called from a different point, he or she may try to optimize communication costs by spliting FIFO into a fifo_head and a fifo_tail object and collocating each of these objects with the object(s) using it. However, the two objects fifo_head and fifo_tail together exhibit the same behaviour as the FIFO object. The concurrency constraints are the very same. In both cases concurrency control has to serialize calls to retrieve and store as soon as the buffer contains, at most, one element. But this uncovers an inconsistency. The same functional behaviour with identical concurrency control requirements requires totally different descriptions according to whether distribution has to be considered or not. Currently there is no possibility for reuse among a distributed and a non-distributed solution to the FIFO buffer problem. While this may be una-voidable in many cases for the pure functional behaviour, as the notion of locality is different3Abb. 2.1Example: FIFO bufferbetween distributed and non-distributed descriptions, concurrency control should not directly be affected by such a design decision. Decisions made by concurrency control are the same whether functional behaviour is implemented using a single object (FIFO) or several objects (fifo_head and fifo_tail).The example above makes obvious the need for concurrency control which are able to handle constraints spanning several objects: when the combined behaviour of these objects constitutes a behaviour which would be specified using a single object as long as distribution is not to be considered. The example also illustrates the observation that concurrency constraints do not de-pend on the actual implementation of the corresponding functional behaviour. In the same way a functional description just relies on a specific behaviour of concurrency control without being interested in the details of how this behaviour is being achieved.This observation can be extended to object structures whose behaviour can not easily be captu-red by specifying a single object, as is the case when that behaviour is built on distribution. It can be viewed as a special case of the principle of separation of concerns. It also leads to the conclusion that this principle is important not only in the case of specifying behaviour of a sing-le object but also in the case of describing concurrent behaviour of object structures.3 A model for concurrency controlNow, that the problem has been outlined, it is necessary to look at how concurrency control ope-rates. Figure 3.1 pictures the dependencies involved with concurrency control. This structure can be observed even in current declarative approaches to concurrency control ([Deco89],[-Neus91],[McHa91]). As a first step it will be interpreted in terms of single object concurrency. 4In this context concurrency is recognizable as concurrent requests pending for processing at the encapsulation border of an object. Execution of these requests is controlled by concurrency constraints as specified at the interface of that object.Concurrency constraints are expressed in terms of an abstract state. However, this abstract state can in no way refer to information from the internal state as this information is hidden behind the encapsulation border.In order to solve this dilemma one could try to infer the current abstract state from the knowled-ge of the initial state and monitoring requests of an object. Such monitoring, though, is inaccu-rate due to indeterminism resulting from concurrent execution of requests. As long as such in-determinism does not occur, state inference could be considered a possibility.The figure above is intended to suggest a different solution. While the interface is not allowed to violate encapsulation nor to access the internal state defined by the actual implementation, this implementation is allowed to provide information about that internal state for its environ-ment. This means that a programmer, during implementation of the behaviour of an object, also has to define how this implementation maps into the behaviour specified at the interface.As, during implementation, a programmer already has to consider whether this implementation really conforms to the interface specification it does not seem to be a problem to make him or her state this conformance explicitly. This can be accomplished by providing a mapping from internal state to abstract state. It is, however, obvious that this mapping, as it only maps state information, can only be part of the conformance considerations to be performed by program-mers.In the case of single concurrent objects, it is tempting to describe how concurrency control in-fluences processing of requests in terms beyond the scope of the object model. Being an intrinsic property of objects, concurrency control may be explained using any model suitable for descri-bing the effects of concurrency control on the execution of requests. If concurrency constraints may be applied to a group of objects this freedom is lost. The semantics established by the un-derlying object system restricts the set of possible models. The key properties are encapsulation of object states and a communicational model of object interaction.5It is obvious that an approach to handling distributed concurrency, which depends on functio-nality not available to ordinary object interaction, is not acceptable. Any such functionality al-lowing concurrency control to violate encapsulation would have disastrous effects on the se-mantics of objects. Functionality allowing influencing of object communication would compli-cate the understanding of object interaction. Thus, influencing concurrent execution within a group of objects has to be based on available object interaction semantics. This leaves two pos-sibilities. Either interpose filter objects into communication paths or make objects explicitly in-teract to perform concurrency control.Interposing communication paths easily fits into the composition-filters model as proposed in [AkBV92]. This approach uses filters specified as part of the interface of an object to interpose and control messages directed to that object. While these filters can easily be used to perform concurrency control in the context of a single object, they are yet too weak to perform concur-rency control on object groups. Concurrency constraints over a group of objects would require interaction among the controlling instances. If these controlling instances are implemented using composition filters, these filters need to be able to cooperate. Consequently a filter would be required to process and consume some of the messages directed to its object and to send mes-sages to other objects involved in a concurrency control relationship. Being part of the object interface, the concurrency control behaviour is tied to the object description. In order to allow reuse of concurrency control descriptions one needs a semantics and mechanisms for reuse of filters. Separating filters from objects will result in definition of filter objects. However, using filter objects for interposing object interaction suffers from naming problems. A client of an ob-ject has to name and address the correct filter object to get to the object actually performing the request.4The cooperative approachIn this section an alternative to realizing concurrency control by interposing object interaction is proposed. It directly follows the concurrency control model presented above. It follows the principle of separation of concerns by encapsulating individual aspects of a behaviour into in-dividual objects.Encapsulation does not restrict an object to performing concurrency control within the bounds of that object. This allows one object to call upon another object to perform concurrency control. By doing this, concurrency control is no longer an intrinsic property of an object. Instead, a be-haviour formerly exhibited by a single object is now represented by the combined behaviour of a group of interacting objects. It is obvious that such a model is applicable to configurations al-ready consisting of a group of interacting objects.Now the world of objects is divided up into two partitions; objects providing arbitrary functional behaviour and objects providing concurrency control needed by the former. But it has yet to be explained how these concurrency control objects can perform their operation. It already has 6been remarked that there is no legal possibility for controlling method execution from outside an object. This, too, has to be initiated from inside that object. However, now all elements of the cooperative approach are available and may be combined to form a homogenous picture.When an object needs a decision from a (concurrency) control object it calls a method from that control object. With this call the object may pass, as parameters, any information needed by the control object to perform the decision. The decisions performed by the control object are actual-ly about whether an executing request within the calling object may proceed or not. Such a deci-sion is performed by delaying an answer to a decision request until the calling executing request may proceed. The object is awaiting this decision either by waiting for the response implicitly, in the case of synchronous communication semantics, or by explicitly requesting an answer in the case of asynchronous communication or wait-by-necessity semantics. When the execution of requests within an object changes state in a way influencing concurrency control, that object may inform an appropriate control object about this state change also using method calls. The combination of all information available to a control object determines the abstract state model available to this control object for performing concurrency control requests.According to the interface control model of concurrency control, starting the execution of a re-quest is the only point to which concurrency control decisions are applicable. However, the more complex a method is the more likely it is for this method to cover sections of different con-currency constraints [Mack84]. This suggests the allowance for method substructures to be made visible at the interface of an object. With this, transitions among these method components also constitute points where concurrency control decisions are required.Introduction of method substructures also suggests a possibility for cleanly integrating the calls to a control object into implementation and into interface description of an object. The sub-structure of a method can be interpreted as a block structure as known from imperative program-ming languages. Upon entry of a block, a call to a control object is performed. Parameters of that call communicate necessary information. The block is entered and execution continues as soon as the call returns. On exit of that block another call to the control object is performed. This is used to inform the control object that execution of this block by the current executing request is being terminated. This also communicates state changes caused by executing this block to the control object.The control object, as it is itself an ordinary object, conforms to a type. This type is mediated by the signature of the methods of that object as observable from an object using this control object. A control object is not part of an ordinary object using it, but gets connected to this or-dinary object at instantiation time of this object.It is easy to employ several control objects from a single object, as there is no distinction bet-ween these control objects and any other object known as far as object interaction is concerned. However, this only works if these different concurrency control objects manage distinct inde-pendent concurrency constraints, not only independent in semantics but independent in compo-nents operated upon. Concurrency constraints intended to be expressed independently require the introduction of an additional level of indirection, a kind of composing control object which implements the composition of the independent constraints.7An example§ 5For simple composition rules it would be possible to integrate composition with the control ob-ject interaction semantics. For example, an AND-operation on constraints would require the more restrictive constraint to be queried first. This occurs with the example of a buffer which is superimposed a request-release-constraint. Execution might only continue after all constraints affected granted access. The example of a privileged reader in a multiple reader/single writer context, who will be granted access even in the presence of active writers, illustrates an OR con-junction, which is required the granting of continuation as soon as the privilege constraint grants continuation. These two examples make it clear that it is better to realize constraint composition using a special object than to try to force it into calling semantics for control objects while loo-sing homogeneity among object interaction semantics.5An exampleFigure 2.1 introduced the FIFO buffer example. The behaviour of such a buffer can be formu-lated using a declarative description based on synchronisation counters as follows: retrieve:N > 0start(retrieve)⇒inc(N)store:N <MAX end(store)⇒dec(N)In this case N denotes a synchronisation counter,MAX denotes the upper bound on the buffer, start(a) and end(a) refer to the start respective termination of the given method, and inc(N)and dec(N) denote increment and decrement of the counter denoted by N.The processing of requests within a FIFO buffer object can be illustrated using the following description in a hypothetical language:8§ 5An example{CNTRL:param class buffer_cntrl type buffer_cntrl_type;// other declarations …retrieve:() fifi-> (…){CNTRL.enter_retrieve(…);// implementation of retrieveCNTRL.leave_retrieve(…);}store:(…) -> (){CNTRL.enter_store(…);// implementation of storeCNTRL.leave_store(…);}}The argument declarations of retrieve and store have been left out for brevity. The argu-ments passed at the calls to CNTRL depend on what information a (control) object of type buf-fer_cntrl_type is expecting. In the case of this simple example, no arguments need being passed at all.Figure 5.1 pictures possible configurations available with cooperative concurrency control to solve the FIFO buffer problem.The“single object” case illustrates the structure, that ordinary objects will exhibit under coo-perative concurrency control. An object (FIFO) implementing functional behaviour (actual buf-fering of items) cooperates with a control object (CNTRL) managing concurrent execution of requests.If the functional behaviour is for some reason distributed among several objects (head and tail), the situation that is labeled distributed buffer - central control is to be encountered. The internal state of the participating functional objects is mapped onto a common abstract state managed by the central control object (CNTRL). Each participating functional object contributes to the com-posite behaviour. It is worth noting, that from the control objects point of view, it does not matter how state and functionality are actually distributed among the functional objects as the central control object still operates on a central view of the composite configuration.In order to efficiently exploit communication properties caused by distribution control objects also have to be split into several parts. This configuration is pictured as distributed buffer -distributed control. It requires special control objects (CNTRL head and CNTRL tail) which use§ 5 An example Arraya suitable distributed concurrency control protocol to implement a distributed view of the ab-stract state of the (distributed) FIFO buffer managed. The functional part of this configuration is identical to the case using central control.This illustrates how cooperative concurrency control allows for independence among imple-mentation of functional and concurrency control behaviour. Changes in the actual implementa-tion of functional behaviour do not cause any changes in the implementation of concurrency control. Functional behaviour need not know anything about the actual realization of concur-rency control.§ 6Conclusions6ConclusionsResearch in inheritance in the context of concurrent objects uncovered the principle of separa-tion of concerns. This paper has presented the concept of cooperative concurrency control. Coo-perative concurrency control separates functional aspects and concurrency control aspects of the behaviour of an object into independent objects. These objects use normal object interaction to achieve the behaviour of the original object via cooperation. Concurrency control objects, en-capsulating concurrency control behaviour, are used by objects realizing functional behaviour. They perform concurrency control decisions. The connection between functional objects and concurrency control objects includes the type of the control object. It is established, for examp-le, by parametrization at instantiation time of a functional object.The cooperative approach is consistent with the notion that an object is responsible for the cor-rect execution of its methods in the context of a concurrent environment. It strictly follows the principle of separation of concerns. As it is based on mechanisms already available with object systems (namely object interaction and parametrization), it is applicable to a variety of current object-based and object-oriented programming languages. Reuse of components (functional ob-jects and concurrency control objects) is available as long as the underlying language does sup-port it.Besides the practical use of cooperative concurrency control, this approach constitutes a base for investigating concurrency control in distributed environments. Declarative approaches on specifying concurrency control can be implemented using cooperative concurrency control. This is due to the flexibility of abstract state specification allowed by modelling abstract state using state information provided with parameters from calls to control object methods. Decla-rative concurrency control specifications, together with a semantics of such specifications, also provide the possibility of deriving from them an actual implementation of a control object. Re-search in this domain could try to integrate declarative concurrency control with framework concepts currently researched and try to describe semantics of concurrency control in terms of cooperative concurrency control.7ReferencesAkBV92M. Aksit, L. Bergmans, S. Vural: “An Object-Oriented Language-Database Integration Model: The Composition-Filters Approach”,ECOOP ‘92 EuropeanConference on Object-Oriented Programming, LNCS 615, 1992BeAk92L. Bergmans, M. Aksit: “Reusability Problems in Object-Oriented Concurrent Programs”,ECOOP 92 Workshop on concurrency,position paper, 1992Caro90 D. Caromel: “Concurrency: An Object-Oriented Approach”,TOOLS 2, pg 183-197, 1990References§ 7Deco89 D. Decouchant, S. Krakowiak, M. Meysembourg, M. Riveill, Rousset de Pina: “A Synchronisation Mechanism for Typed Objects in a Distributed System”,Proc. ofthe ACM SIGPLAN Workshop on Object-Based Concurrent Programming,SIGPLAN, 1989Frøl92S. Frølund, “Inheritance of Synchronisation Constraints in Concurrent Object-Oriented Programming Languages”,ECOOP ‘92 European Conference on Object-Oriented Programming, LNCS 615, 1992Geib92J.-M. Geib, L. Courtrai: “Abstractions for Synchronization to InheritSynchronisation Constraints”,ECOOP ‘92 Workshop on concurrency, positionpaper, 1992Holl92I. Holland: “Specifying reusable components using Contracts”,ECOOP ‘92 European Conference on Object-Oriented Programming, LNCS 615, 1992John91R. Johnson, V. Russo: “Reusing Object-Oriented Design”,University of Illinois, Technical Report UIUCDCS 91-1696, May 1991Neus91 C. Neusius: “Synchronizing Actions”,ECOOP ‘91 European Conference on Object-Oriented Programming, Springer Verlag, 1991Mack84L. Mackert: “Modellierung, Spezifikation und korrekte Realisierung von asynchronen Systemen”, Dissertation, Arbeitsberichte des IMMD, Bd. 16, Nr. 7,1984Mats90S. Matsuoka, K. Wakita, A. Yonezawa: “Analysis of inheritance Anomaly in Concurrent Object-Oriented Languages”,ECOOP/OOPSLA ‘90 Workshop onObjekt-Based Concurrent Systems, Aug 1990McHa91 C. McHale, B. Walsh, S. Baker, A. Donnelly: “Scheduling Predicates”,Trinity College, Dublin, Technical Report TCD-CS-91-24, 1991Shiba91 E. Shibayama: “Reuse of Concurrent Object Descriptions”,Concurrency: Theory, Language and Architecture, LNCS 491, 1991Wegn87P. Wegner: “Dimensions of Object-Based Languages”,Proc. of OOPSLA 1987, SIGPLAN, vol. 22, no. 12, pg. 168-182, 1987。
数据库理论笔记_19_并行控制(concurrencycontrol)

数据库理论笔记_19_并⾏控制(concurrencycontrol)之前讲的都是概念,关于实际怎么防⽌调度读到或者写到⾃⼰不该写的东西我们其实⼀!点!都!没!讲!啦啦啦实际中实现isolation这个性质的机制有两种,⼀种被称为TWO_PHASE LOCKING 还有⼀个被称为snapshot isolation,前⾯那个字⾯就很好理解,⼆步锁定,后⾯那个直接翻译被称为快照隔离。
下⾯我们讲的是锁定。
锁定分为两种:shared,即分享锁定,这个被分享锁定所锁定的数据可以被其他的调度套上分享锁定。
这个锁定的拥有者对于锁定数据的操作权限仅限于读取数据。
exclusive, 即排外锁定,被这种锁锁定的数据不能被其他的任何调度锁定,被锁定的数据可以被持有锁定的调度读和写。
在这⾥需要介绍⼀个新的概念叫做concurrency control manager.这个系统负责控制数据库⾥所有的锁定需求。
锁的兼容定义见上。
我们定义LOCK-S(Q)为⽤share模式锁定数据Q,LOCK-X(Q)为⽤excluded模式锁定数据Q,UNLOCK(Q)来取消锁定Q。
下⾯进⾏对于锁定的两种使⽤⽅式的讨论。
理解上图以后我们发现,display(A+B)显⽰出的结果不是正确的,因为T1过早的解锁了B数据,⽽它本⾝的活动还没有完结,⽽事实上我们也很明⽩这个结果必然是错的,因为T1的剩下部分中有写的部分,这样的调度并不属于⼀个serializable的调度。
所以事实上这个情况属于T1过早的解开了锁,导致的数据不连续。
⽽当我们这么写的时候,就不需要担⼼不连续了,但是很明显的,这个调度并跑不起来,原因是显⽽易见的。
⽽这种相互卡死的情况被称为锁死,当遇到锁死的时候,必然伴随着回滚,⽽回滚同时也会将原来锁死的数据解锁。
⽽在设计模式的时候我们就遇到了这个问题,我们到底是要锁死还是要数据不连续——很明显前者好⼀点,因为可以通过数据回滚来解决,⽽数据不连续导致的外部输出是很难解决的。
Under consideration for publication in Formal Aspects of Computing Concurrency and Refineme

Under consideration for publication in Formal Aspects of ComputingConcurrency and Refinement in the Unified Modeling LanguageJim Davies and Charles CrichtonOxford University Computing Laboratory,Wolfson Building,Parks Road,Oxford,UKAbstract.This paper defines a formal semantics for a subset of the Unified Modeling Language(UML). It shows how suitable combinations of class,object,state,and sequence diagrams can be associated with patterns of interaction,expressed in the event notation of Communicating Sequential Processes(CSP). The diagram semantics is then extended to give a meaning to complete models—suitable combinations of diagrams—and thus a concurrency semantics for object models written in UML.This model semantics is in turn used to define a theory of refinement,based upon existing notions of data and process refinement. Keywords:Unified Modeling Language;Object-oriented Design;Object Modelling;Concurrency;Refine-ment;Communicating Sequential Processes.1.IntroductionThe evolution of the Unified Modeling Language(UML)[OMG01]is of tremendous significance for the field of software engineering.The definition of a single framework in which to place the sketches,diagrams, pictures,and formulae that shape and communicate our understanding of complex designs is a welcome development,and the widespread acceptance of this framework makes it an ideal vehicle for the application of formal,mathematical techniques.In this paper,we show how object models described using the diagram notations of UML can be au-tomatically translated into a formal language of interaction:Hoare’s Communicating Sequential Processes (CSP)[Hoa85].The behavioural properties of these designs—the order in which messages may be sent, the possible consequences of concurrent execution of certain operations,whether a particular scenario is possible—can then be calculated and explored.We show also how the existing refinement orderings defined upon processes can be applied to the be-havioural refinement of object-oriented designs.The question of whether one design is a suitable refactoring of another can be reduced to a question of behavioural refinement:that is,a question of whether every behaviour of one design is allowed for in the description of the other.The resulting theory of refinement for object models is supported by existing refinement-checking technology[FSE].Our translation requires more than just a semantics for the individual diagram notations:it requires a Correspondence and offprint requests to:Jim Davies,Oxford University Computing Laboratory,Wolfson Building,Parks Road, Oxford,OX13QD,UK.e-mail:Jim.Davies@2J.Davies and C.Crichton behavioural semantics for the models that are produced when these notations are used in combination.We will express both diagram and model semantics in terms of CSP events and processes.As our aims include facilitating automatic analysis,we will employ the machine-readable dialect of CSP[Ros97],which can be used as input to animation and refinement-checking tools.The paper begins with a review of the various diagram notations that we have chosen to support: class diagrams,object diagrams,state(or statechart)diagrams,and sequence diagrams.This is followed, in Section3,by an explanation of how these diagrams can be given a behavioural semantics in terms of machine-readable CSP.In Section4,we show how the diagram semantics can be extended to give a meaning to complete object models,in terms of the sequences of actions that may be performed,and the sets of actions that may be blocked.We show how—by associating state diagrams with operations—we can create models that are adequate for the description of the concurrent execution of multiple operations upon the same object.This model semantics can be used to define theories of refinement for object models written in UML. In Section5,we show how different notions of process and data refinement can be put to practical use in the analysis and development of object models written in UML.The paper ends with a discussion of the prospects for automated analysis,and a review of related work.2.Object modellingA model in UML is a collection of diagrams,illustrating different aspects of a design,together with related properties or requirements.Each of these diagrams conveys some information about the architecture,at-tributes,and behaviour of the system being modelled.As we might expect,the UML documentation asserts that“Every complex system is best approached through a small set of nearly independent views of a model. No single view is sufficient.”[OMG01,Section1.2.2]We might expect,too,that two different models—two different combinations of diagrams—could be used as descriptions of the same system.To demonstrate the use of the different diagram notations,we will consider a model of a simple com-munication protocol,whose only dynamic property of interest(at our chosen level of abstraction)isflow control:the transmitter waits for an acknowledgement that a message has been output by the receiver before accepting another for transmission.In each case,our interpretation of the diagram notation will be just one or many possible interpretations: other semantics may be defined with different purposes in mind.Indeed,even the formal translations that we produce could be completed in different ways.The processes that we use to represent the implicit mechanisms for event communication and operation invocation are just one way of resolving the semantic variation points in the UML specification[OMG01].2.1.Class diagramsA class diagram identifies the entities in the system,and describes the potential relationships between them.It provides structure to a behavioural semantics—giving the signatures of objects—and places constraints upon reachable configurations,but does not directly describe the behaviour of any component.Such a diagram comprises a number of class boxes,and a number of lines—representing associations—between them.Each class box may have up to three partitions below the name box,listing attributes,operations,and signals,respectively.Some associations may be implemented as attributes:in this case,the value of the attribute is a reference to another object(or a collection of objects).An association line can show the navigability of the relationship(using arrowheads),its multiplicity,and the names used in reference.The operations of a class may be described as synchronous or asynchronous,and may be subject to different degrees of concurrency control:the concurrency attribute of an operation explains whether that operation may be invoked concurrently with other operations on the same object.The class diagram may describe also the signature of each operation:the argument and result types.A typical implementation for an UML operation is a method or function call in the target programming language.Signals are an abstract,asynchronous means of communication.Although signals may be implemented in the same way as operations,they are more likely to correspond to sequences of calls,perhaps involving the use of a package or library that has not been modelled.The class diagram may list the names of the signals that can be received by each class.Concurrency and Refinement in the UML3Fig.1.A class diagram for the simple protocolFig.2.An object diagram for the simple protocolA class diagram may include also information about inheritance:which classes are defined as extensions of others.This may have a bearing upon the behavioural semantics,in that there may be a choice of (implementations of)operations that could be invoked in response to a particular call.The structure of our semantics allows for the subsequent addition of a selection mechanism,but the automatic determination of such a mechanism from information in the class diagram is left as a subject for separate,future study.The class diagram for our simple protocol is given in Figure1;it identifies the two main protocol components—a transmitter and a receiver—as well as two abstract,interface entities—a user and a lis-tener.The association between the transmitter and the receiver tells us that each is capable of referring to the other.The transmitter will use the name rec for the receiver object that it knows about;the receiver will use the name trans for the transmitter object.The associations are all1to1:a user object will refer to a single transmitter object,a transmitter will refer to a single receiver,and a receiver will refer to a single listener.In this model,the listener is unable to refer to the receiver:the association between these two classes is navigable only in the other direction.All communication in this model is described in terms of signals:the user may send an in signal to the transmitter,which may send a message signal to the receiver,which may send an out signal to the listener. The receiver may send an ack signal to the transmitter,which may send a ready signal to the user.The class diagram tells us which events may be sent;the state diagram will tell us how the arrival of one event may trigger actions,such as the sending of another event.2.2.Object diagramsObject diagrams are class diagrams in which only instances—or objects—are present.Such a diagram can be used to describe a particular state of the system,or to characterise a region of the state space—each object may be annotated with a constraint upon attribute values.In a behavioural semantics,an object diagram can be used to describe an initial configuration.In the object diagram of Figure2,the association instance(or link)between transmitter and receiver is stereotyped as reliable,to indicate that signals are reliably transmitted between the objects.In UML,the fact that two objects are linked in an object diagram does not mean that communication between them is necessarily reliable,whether in terms of signal transmission or operation invocation.4J.Davies and C.CrichtonFig.3.State diagrams for the transmitter and receiver classes2.3.State diagramsA state diagram describes the behaviour of an object or operation in terms of the performance of actions in response to the arrival of events.We will consider two kinds of events:call events and signal events.The occurrence of a call event corresponds to the beginning on an execution of an operation upon the current object;the occurrence of a signal event corresponds to the successful arrival of a signal.The possible effects of an event are described by labelled transitions between states in the state diagram.Each transition may be labelled with a trigger event,a guard,and a sequence of actions.If an event occurs,and there is a corresponding transition starting from the current state,then the guard is evaluated.Should the guard prove to be true,based on the values of the object attributes,and any attributes associated with the event itself,then the sequence of actions will be performed:the future behaviour of the object is then described by the target state of the transition.Should the guard prove to be false,then the event will be discarded,and the object will remain in the current(source)state.Some of the transitions in a diagram may have no trigger events:these are called completion transitions, and arefired as soon as the source state is entered(and any entry actions have been completed).An important feature of the state diagram language is the run-to-completion property:following the occurrence of an event, no further events will be accepted until every action triggered by that event,including those associated with any subsequently-enabled completion transitions,has been performed.The state diagram notation contains many other features:notably,entry and exit actions,change events, prioritised and timed transitions,and composite states.The semantics of diagrams using entry and exit actions is easily derived from the semantics of equivalent diagrams in which these actions are prepended and appended to the relevant transitions.The other features require extensions to the semantics presented here: suitable extensions are discussed in Section7.Figure3presents two state diagrams:one for the transmitter class,and another for the receiver.A transmitter object can be in one of two states:it is ready for a new message from its client,or it is waiting for an acknowledgement from the receiver.The arrival of a new message m is represented by an occurrence of the event in(m);this has the effect of sending a signal message(m)to the receiver rec.There is no blocking of signal events:unless it is still completing a sequence of actions triggered earlier, an object will accept any signal.However,if there are no transitions labelled with that signal,and if it is not explicitly deferred by the current state,then the signal will be immediately discarded.In Figure3,if an in event arrives while the transmitter is in the Waiting state,then it will be discarded;similarly,if an ack arrives when the transmitter is in the Ready state,then it will be discarded.Concurrency and Refinement in the UML5Fig.4.A sequence diagram2.4.Sequence diagramsA sequence diagram describes a scenario in terms of messages sent between various objects.The messages are presented as horizontal lines labelled with the name of an event or operation.The objects are boxes with a vertical,broken line descending from them;the objects may be anonymous,or they may be named according to the attributes and associations presented in the class diagram for the current model.The vertical,broken lines—called lifelines—are used to impose a temporal order upon the messages presented.Where two message lines begin(or end)at the same lifeline,the message whose line is nearer the top of the diagram must be sent(or received)before the other.Moving down a lifeline corresponds to the passage of time.A sequence diagram may represent the creation(or destruction)of one of the objects involved by explicitly starting(or ending)a lifeline within the diagram.In the sequence diagram of Figure4,all of the objects have been created before the scenario,and none are destroyed during it.This diagram illustrates a desirable behaviour of our simple protocol,in which a single message m is passed from the User to the Listener via the two objects of our protocol.The features presented here form only a small subset of those available within the sequence and interaction diagram languages of UML.Our use of the notation here is purely as an indication of what could be achieved.2.5.Operation diagramsThe UML documentation admits the possibility of multiple,concurrent calls of operations upon a single object.Each operation has a concurrency attribute,which may take one of three values:•sequential:concurrent calls on the same object should be avoided;•guarded:concurrent calls are permitted,but the operations will be executed sequentially;each new execution will be blocked until the previous execution has completed;•concurrent:concurrent calls are permitted,and the operations may be executed concurrently;the cor-responding sequences of transitions and actions may be interleaved.This information—which would normally be presented in the class diagram—can be carried forward from the model to an implementation,using features such as the synchronized mechanism in Java.If we attempt to include information about the progress of multiple executions of different operations within a single‘object’state diagram,the result is likely to be unreadable.The possibility of concurrent execution multiplies the number of states that may be of interest;any operation may be associated with a state space of its own,describing its progress through the various actions and conditions that its performance may entail.The effect of an action may depend upon the value of temporary variables or objects—the local state of the current execution—as well as the value of object attributes.6J.Davies and C.CrichtonFig.5.Printer class diagramFig.6.Printer state diagramEven the behaviour of a class with a single operation could become difficult to describe if this operation had more than two points at which it reads from,or writes to,the attributes of the object.Such an approach would require also a relaxation of the run-to-completion assumption for state diagrams:if a single diagram is to describe the effect of concurrent execution,then the underlying state machine must be able to accept a second call event before the action sequence corresponding to thefirst has been completed.The only practical solution is to use a different state diagram for each compound operation:that is,for each operation that has more than one point of interaction with the shared state;the effect of any other, atomic operation can still be represented as a single transition,triggered by a call event,on the main state diagram.We will use the term operation diagram for a state diagram that has been used to describe the behaviour of an operation.As an example of this approach,consider how we might describe the behaviour of objects of the Printer class shown in Figure5.Objects of this class have a single,integer-valued data attribute called alarm,and two operations print and service;neither operation expects an argument or a return value.There are also several signals:start,stop,open,and close.The object state diagram for the printer class is shown in Figure6.This diagram does not include call events for either operation,but instead shows how the state space of the printer object can be partitioned into two regions:Idle and Printing.The difference between the two regions lies in the effect of the open event:if the current state of the printer is in Printing,then this event leads to a state in which all events will be ignored,and both operations will be blocked;this last effect is achieved by setting the single attribute alarm to a non-zero value.Each operation is described by a separate operation(state)diagram:both are shown in Figure7.The labelling of the initial transitions is a(suggested)notational short-cut,indicating that the execution should be blocked if this condition is not true.The same result can be produced by adding an additional state, immediately following the initial one,with a guarded choice of completion transitions.In this example,the two operations do not make assignments directly,but instead act upon the shared state by sending signals. Apart from fulfilling the original need for a model that can describe concurrent execution,this approach hasConcurrency and Refinement in the UML7Fig.7.Printer operation state diagramsthe additional advantage of separating two concerns:the definition of(an abstraction of)the state,and the description of the operations.We should emphasise that it is impossible to describe the effects of concurrent execution,or the invocation of an operation upon the current object,without adopting this operation diagram approach(as a corollary, we might observe that it is thus impossible to describe recursive operations in a single UML state diagram). The only alternative would be to relax the run-to-completion assumption,which would render the state diagram notation all-but-unusable.The language of operation diagrams is a sublanguage of that of state diagrams:an operation diagram cannot accept call events,except for the initial,implicit call event that creates an instance.The state diagram that describes the chosen abstraction of the attribute state may have call events,but only for operations that are atomic at the current level of abstraction.3.Diagram semanticsTo construct a formal semantics for a UML diagram,we require a mapping from the graphical constructs to some mathematical domain:this mapping is a formal equivalent of the existing informal semantics for the diagram language—an explanation of what each construct means.There are many ways in which we might define this mapping,depending upon the purpose to which the resulting semantics will be put.As is the case with programming languages,a likely purpose for a formal semantics is to predict and reason about patterns of behaviour.Architectural and static properties are relatively easy to deduce;it is behaviour—and in particular,concurrent behaviour—that is harder to comprehend.For that reason,we will concentrate upon the construction of a formal semantics that is adequate for the analysis of behaviour:one that tells us how the system as described may evolve,in terms of interactions visible at its interface.In this section,we explain how individual diagrams may be mapped to processes; in the following section,we will see how to combine these processes to obtain the semantics of a complete model.Our presentation here is exemplary:an explicit semantic function would need to map documents that define UML models to documents that define CSP representations.In this paper,we describe this function in terms of its effect upon simple UML models.Its implementation,which requires mechanisms for namespaces, dynamic binding,and polymorphic channels in CSP,is a challenge in itself.3.1.Process notationIn the language of CSP,processes are defined in terms of the occurrence and availability of abstract events: atomic,synchronous,communications.In the machine-readable dialect,events are introduced as elements of channels.For example,the declarationchannel c:A.B8J.Davies and C.Crichton introduces a set of compound events,each of the form c.a.b,where a is drawn from the set A and b is drawn from the set B.Following such a declaration,we may use the expression{|c|}to refer to all of the events whose names start with the prefix c.The prefix process a->P is ready to perform the event a;if this event is performed,the future behaviour of this process is described by term P.The symbol[]denotes an external choice of(sets of)behaviours:a menu of possible interactions.The external choice symbol may be used in both binary and indexed forms. For example,the process[]i:I@a(i)->P(i)represents an external choice over all of the processes a(i)->P(i):the resulting process is ready to engage in any event of the form a(i),for i in I,and then behave as the process P(i).The input choice expression c?x->P(x)represents an external choice in which every alternative begins with an event from the channel set{|c|}.The corresponding output expression c!v->P is no choice at all:any variables appearing in the value expression v must already have been declared.(The process language is declarative,in that any variable takes a value at the point of declaration,and retains that value for the remainder of its scope).We will often use a combination of?and!to abbreviate a complex,indexed external choice over a set of compound events,in which some components are already determined.The expression c?x!d?y!e->Pdenotes an external choice in which the values of x and y—the symbols preceded by a question mark—are drawn from the set of all possible values for that component of the channel,and the values of d and e are fixed.We might expect the future behaviour P to be parameterised by x and y.The internal choice symbol|˜|denotes an internal choice of(sets of)behaviours.A process described as P|˜|Q will behave as P or as Q.The choice is not exclusive,in that both alternatives may be made available.We use this notation to represent a choice made within the current component,or—at least—on the far side of this interface.For example,the(indexed)internal choice|˜|i:I@P(i)represents a component whose behaviour may be any of P(i).(In the machine-readable dialect,the indexing set I must befinite).The interrupt operator/\has the effect of adding an external choice to every event menu present in the expansion of itsfirst argument.For example,(a->b->P)/\Q=a->b->(P/\Q)[]Q[]QWe will use this operator P whenever we have a complex pattern of behaviour that may be interrupted—permanently—by the beginning of another pattern Q.Processes are usually composed using a binary parallel operator,which specifies the set of events to be shared between its two arguments:the set of events that can occur only if performed simultaneously by both processes.The expression P[|A|]Q denotes the parallel combination of two processes,P and Q,sharing every event in the set A.If the shared set is empty,we write|||,rather than[|{}|].Either form of parallel combination may be used in prefix,indexed form;as in the case of internal choice,the indexing set must befinite.In CSP,sharing does not entail concealment:shared events remain visible,and may be subsequently shared with other components.The hiding operator is used to conceal,or internalise,sets of events:the expression P\A denotes a process that behaves exactly as P,except that events from the set A are no longer visible:they may not be shared with,and do not require the cooperation of,other processes.As processes are defined entirely in terms of their(remaining)external events,use of the hiding operator may mean that the resulting process is undefined,or divergent.This situation is quite different from that of the(fully-defined) process STOP,which can perform no events,and is used to represent the end of a pattern of behaviour.Concurrency and Refinement in the UML9 The let...within...construct allows for the scoping of process names;definitions made between let and within apply only for the term immediately following within.There are Bool and Int datatypes, for Boolean and integer values,respectively.Other types may be introduced using datatype definitions;for example,the definitiondatatype BinaryTree=empty|node.Int.BinaryTree.BinaryTreedefines a type of binary trees with integer values at the nodes.This is only the briefest of introductions to the process language:a more comprehensive introduction can be found in[Hoa85]or[Ros97].3.2.Actions and eventsOur behavioural semantics will be defined as a translation from object models to processes.We must begin, however,with an explanation of how the actions and events of our object models are to be translated into abstract(CSP)events.With the exception of local actions,actions and events will be represented as a compound abstract events,in which two of the components are used to identify the source and target of the abstract communication.If the communication represents the semantics of an operation call,then it may produce one of three results:if the operation in question may be invoked concurrently,and thus has its own operation(state) diagram,then a new state machine will be created to process the event;if the operation may not be invoked concurrently,and does not have its own diagram,then the event will be processed by the state machine representing the object;if the operation is a constructor(a create operation),then it will be processed by the class,and a new state machine will be created,representing a new object.Each state machine will be represented as a separate process.The source and target of each abstract communication will be processes representing state machines: objects,operation executions,or classes.3.2.1.ActionsA call action corresponds to a call of an operation.The start of the action can be represented as a compound event of the formcallAction.from.to.operation.argumentswhere from is the reference of the source process,to is the reference of the target,operation is the name of the operation,and arguments are the call parameters.A return action corresponds to the completion of an operation,from the point of view of the called operation(and its associated object).It can be represented as a compound event of the form returnAction.from.to.operation.valuewhere to is the reference of the original caller object,from is the reference of the original target,and value is the returned value.A send action corresponds to the sending of a signal,and will be represented as a compound event of the formsendAction.from.to.signal.argumentswhere from is the reference of the caller object,to is the reference of the target,signal is the name of the operation,and arguments are the call parameters.A create action corresponds to the creation of a new object.In our semantics,this action will be repre-sented as a pair of compound events:the eventcallAction.from.to.create.argumentsrepresents the beginning of the action,and a corresponding returnEvent its completion.The value associated with this second event will be the reference of the new object created.A destroy action corresponds to the destruction of an object;this is an asynchronous operation,and may be represented as a single event of the form。
casbin java实现原理

casbin java实现原理## Casbin Java Implementation Principles.Casbin is an authorization library that supports access control models like ACL, RBAC, and ABAC. It uses a simple text file or database to store the authorization rules and can be easily integrated into Java applications.The core principle of Casbin's Java implementation is based on the concept of "policy". A policy defines a set of rules that determine whether a user is allowed to perform a specific action on a resource. Each rule consists of a subject, an object, and an action. The subject represents the user or group of users making the request, the object represents the resource being accessed, and the action represents the operation being performed.When a user makes a request to access a resource, Casbin checks the policy to determine if the user is authorized to perform the requested action. If the user isauthorized, the request is granted; otherwise, the requestis denied.Casbin's Java implementation uses a role-based access control (RBAC) model by default. In RBAC, users areassigned to roles, and roles are assigned to permissions. Permissions are then used to control access to resources. This model allows for fine-grained access control, as it is possible to assign different permissions to different roles.In addition to RBAC, Casbin also supports other access control models, such as attribute-based access control (ABAC). ABAC allows for more fine-grained access control by taking into account the attributes of the user, the resource, and the environment.Casbin's Java implementation is highly extensible. Itis possible to customize the policy engine, the storage adapter, and the enforcer to meet the specific requirements of the application.## 卡斯宾 Java 实现原理。
天地图JavaScript API接口说明

JavaScript API接口文档V2.0天地图有限公司2013年3月文档说明本文档包含所有的内容除说明以外,版权均属天地图有限公司所有,受《中华人民共和国著作权法》保护及相关法律法规和中国加入的所有知识产权方面的国际条约的保护。
未经本公司书面许可,任何单位和个人不得以任何方式翻印和转载本文档的任何内容,否则视为侵权,天地图有限公司保留已发追究其法律责任的权利。
本文档是天地图Java Script API的用户使用参考手册,详细阐述了API提供用户的类和方法,以及可以实现的功能介绍。
天地图Java Script API让您可以将地图嵌入您自己的网页中。
API 提供了许多方法与地图进行交互,以及一系列向地图添加内容的服务,从而使您可以在自己的网站上创建稳定的地图应用程序。
本文档分为地图主类、控件类、工具类、叠加物、右键菜单类、实体类、事件类7个大章节。
以类(描述、属性、构造函数、方法)为索引讲述接口用法。
用户在阅读下面的文档时,可以根据需求对文档进行查询或跳跃式阅读。
从而更好地应用API类服务于自己的领域。
JavaScript API 整体概要设计API接口基本结构图API接口类基本关系图目录JavaScript API接口文档V2.0..........................................................................................................................I JavaScript API 整体概要设计............................................................................................................................II 1 地图主类 (5)1.1 TMap类 (5)1.1.1 构造函数 (5)1.1.2 配置方法 (5)1.1.3 地图状态方法 (5)1.1.4 修改地图状态方法 (6)1.1.5 坐标变换 (6)1.1.6 覆盖物方法 (7)1.1.7 控件 (7)1.1.8 地图图层方法 (7)1.1.9 事件方法 (8)1.2 TMapOptions类 (8)1.2.1 属性 (9)1.3 TMapTypeOptions类 (9)1.3.1 属性 (9)1.4 TMapType 类 (9)1.4.1 构造函数 (9)1.4.2 方法 (9)1.4.3 常量 (10)1.5 TTileLayer 类 (10)1.5.1 构造函数 (10)1.5.2 方法 (10)1.5.3 事件 (11)1.6 TTileLayerOptions类 (11)1.6.1 属性 (11)2 控件类 (11)2.1 TControl类 (11)2.1.1 方法 (12)2.2 TNavigationControlOptions类 (12)2.2.1 属性 (12)2.3 TNavigationControl类 (13)2.3.1 构造函数 (13)2.4 TOverviewMapControlOptions类 (13)2.4.1 属性 (13)2.5 TOverviewMapControl类 (13)2.5.1 构造函数 (13)2.5.2 方法 (14)2.5.3 事件 (14)2.6 TScaleControl类 (14)2.6.1 构造函数 (14)2.6.2 方法 (14)2.8 TCopyright类 (15)2.8.1 属性 (15)2.9 TMapTypeOptions类 (15)2.9.1 属性 (15)2.10 TMapTypeControl类 (15)2.10.1 构造函数 (15)3 工具类 (16)3.1 TMarkToolOptions类 (16)3.1.1 属性 (16)3.2 TMarkTool类 (16)3.2.1 构造函数 (16)3.2.2 方法 (16)3.2.3 事件 (17)3.3 TPolygonToolOptions类 (17)3.3.1 属性 (17)3.4 TPolygonTool类 (17)3.4.1 构造函数 (17)3.4.2 方法 (17)3.4.3 事件 (18)3.5 TPolylineToolOptions类 (18)3.5.1 属性 (18)3.6 TPolylineTool类 (18)3.6.1 构造函数 (19)3.6.2 方法 (19)3.6.3 事件 (19)3.7 TRectToolOptions类 (19)3.7.1 属性 (19)3.8 TRectTool类 (20)3.8.1 构造函数 (20)3.8.2 方法 (20)3.8.3 事件 (20)4 叠加物 (20)4.1 TOverlay类 (20)4.1.1 属性 (21)4.1.2 方法 (21)4.2 TLabelOptions类 (21)4.2.1 属性 (21)4.3 TLabel类 (22)4.3.1 构造函数 (22)4.3.2 方法 (22)4.3.3 事件 (23)4.4 TMarkerOptions类 (23)4.4.1 属性 (23)4.5 TMarker类 (24)4.6 TIconOptions类 (25)4.6.1 属性 (26)4.7 TIcon类 (26)4.7.1 构造函数 (26)4.7.2 方法 (26)4.8 TPolylineOptions类 (26)4.8.1 属性 (26)4.9 TPolyline类 (27)4.9.1 构造函数 (27)4.9.2 方法 (27)4.9.3 事件 (27)4.10 TPolygonOptions类 (28)4.10.1 属性 (28)4.11 TPolygon类 (28)4.11.1 构造函数 (28)4.11.2 方法 (28)4.11.3 事件 (29)4.12 TInfoWindowOptions类 (29)4.12.1 属性 (29)4.13 TInfoWindow类 (29)4.13.1 构造函数 (29)4.13.2 方法 (30)4.13.3 事件 (30)4.14 TRectOptions类 (31)4.14.1 属性 (31)4.15 TRect类 (31)4.15.1 构造函数 (31)4.15.2 方法 (31)4.15.3 事件 (32)4.16 TCircleOptions类 (32)4.16.1 属性 (32)4.17 TCircle类 (32)4.17.1 构造函数 (32)4.17.2 方法 (33)4.17.3 事件 (33)4.18 TEllipseOptions类 (33)4.18.1 属性 (33)4.19 TEllipse类 (34)4.19.1 构造函数 (34)4.19.2 方法 (34)4.19.3 事件 (35)5 右键菜单类 (35)5.1 TContextMenu类 (35)5.2 TMenuItem类 (35)5.2.1 构造函数 (36)5.2.2 属性 (36)5.3 TContextMenuOptions类 (36)5.3.1 属性 (36)6 实体类 (36)6.1 TLngLat类 (36)6.1.1 构造函数 (36)6.1.2 方法 (36)6.2 TBounds类 (37)6.2.1 构造函数 (37)6.2.2 方法 (37)6.3 TPixel类 (37)6.3.1 属性 (38)6.3.2 构造函数 (38)6.3.3 方法 (38)6.4 TSize类 (38)6.4.1 属性 (38)6.4.2 方法 (38)7 事件类 (38)7.1 TEvent类 (38)7.1.1 静态方法 (39)7.1.2 事件 (39)7.2 TEventListener 类 (39)1地图主类1.1TMap类此类是天地图地图API的基础类,是地图实例化的基础函数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Concurrency Control with Java and Relational DatabasesS´e rgio Soares and Paulo BorbaInformatics CenterFederal University of PernambucoRecife,PE,Brazilscbs,phmb@cin.ufpe.brAbstractAs web–based information systems usually run in con-current environment,the complexity for implementing and testing those systems is significantly high.Therefore it is useful to have guidelines to introduce concurrency control, avoiding ad hoc control strategies,which may have a neg-ative impact in efficiency and may not guarantee system safety.This paper defines guidelines for concurrency con-trol in web–based information systems implemented in Java with relational databases.In particular,we show where Java and relational database concurrency control mecha-nisms should be used in order to implement our concur-rency control strategy.Additionally,we analyze the perfor-mance of different concurrency controls approaches.The main point of the guidelines is to guarantee system correct-ness without redundant concurrency control,both increas-ing performance and guaranteeing safety.1.IntroductionAs web–based information systems usually run in con-current environment,the complexity for implementing and testing those systems is significantly increased.In fact,sub-tle implementation errors might appear and are usually dif-ficult to detect and locate.This indicates that we need ade-quate ways to implement concurrent programs.In particu-lar,it is useful to have guidelines to introduce concurrency control,avoiding ad hoc control strategies,which may have a negative impact in efficiency,making redundant controls. Moreover,ad hoc control strategies may not guarantee sys-tem safety,adding new race conditions that lead to invalid executions.In order to avoid those problems,the guidelines pre-sented here guarantee safety,standardizing the control strategies,favoring system extensibility,and improving maintainability.Contrasting with general well–known[11, 14]design patterns for concurrency control,our guidelines are more effective for developing web–based systems be-cause they are tailored to a specific architecture widely used to develop this kind of system.They also assume the use of relational databases for implementing persistence,and con-sider the databases concurrency control support.We also analyze the performance of several concurrency controls, identifying the most efficient ones.Since our architecture demands the manipulation of both Java[10]objects and database tables,we must use pro-gramming languages concurrency control mechanisms over the objects.Our guidelines use concurrency control mech-anisms of both Java and relational databases,which are widely used for implementing web–based information sys-tems.The guidelines indicate where each mechanism shall be used in order to guarantee system correctness without re-dundant and expensive concurrency control.Therefore pro-grammers know which concurrency controls must be im-plemented by the database mechanisms and which ones the programming language features must implement.A pes-simist approach can leave all the concurrency control to the database management system.However,this approach does not manipulate objects,avoiding several benefits of the object–orientation.The negative impact on efficiency caused by program-ming language concurrency control mechanisms,and the need for guidelines that support the correct and efficient in-troduction of concurrency control,has been reported by sev-eral researchers[3,1,6].They are worried in guaranteeing execution efficiency,avoiding unnecessary synchronization in Java concurrent programs.Our approach differs in the sense that it is not general,but tailored to a specific architec-ture and considers both language and database concurrency control mechanisms.Although specific,a wide range of ap-plication can be developed using this architecture.Some examples are shown in the next section.We applied our guidelines to two real web–based infor-mation systems.In thefirst one,which was already imple-mented and running,we used the guidelines as a mechanism for checking whether the system controls concurrency cor-rectly.This helped us to validate the guidelines,since someconcurrency control that our guidelines define was used in those systems,such as using transactions only when it isnecessary.In the second system,the guidelines were ap-plied during the implementation phase and were responsible up to10%for the implementation time,which demonstratethe small impact of them.This paper is structured infive sections.In Section2we present a specific architecture to developing web–basedinformation systems.After that,in Section3,we define the concurrency control guidelines,which aim to guaranteesafety and efficiency.We identify the mechanism(databaseor programming language)that should be used in each sit-uation of the presented architecture.We discuss the perfor-mance impact of different concurrency control approaches in Section4.Related approaches and conclusions are pre-sented in Section5.2.A Specific Architecture for Web–based Sys-temsThis specific architecture,which the guidelines are tai-lored in,tries to provide some requirements that can be con-sidered general to web–based information systems,includ-ing the ability to work in a distributed environment,guar-antee data integrity and persistence in production environ-ment,possibility to change the persistence mechanism,or use volatile data,for requirements validation,and be easilymaintained.In order to attend those requirements a layerarchitecture and design patterns were used in a Java im-plementation.This layer architecture aims to separate datamanagement,business rules,communication(distribution), and presentation(user interface)concerns.Such structureprevents tangled code,for example,business code interlac-ing with data access code,and design patterns allow us to reach greater reuse and extensibility levels.Figure1presents an UML[4]class diagram that illus-trates the software architecture and design patterns[13,9,5] considered here,for a simple bank example.Accesses tothe system are made through a unique entry point,the sys-tem facade[9]().The system facade also implements the Singleton[9]design pattern to guarantee that there isjust a single instance of this class,which is the instance to be distributed over the user interfaces.The facade is com-posed of business collections,target of facade methods del-egation.Accounts are registered,updated,and queried in a web client implemented using Java Servlets technology. Section3provides more details about the classes of the soft-ware architecture.Although the guidelines presented in this paper havebeen defined for a specific layer architecture and associated design patterns[13],this architecture can be used to imple-ment several kinds of system,but it is especially usefulforFigure1.Architecture’s class diagram.the development of web–based information systems.3.Concurrency Control GuidelinesIn this section we indicate the concurrency control mech-anisms(programming language or database)that should be used in each part of the code structured according to thepattern presented in the previous section(see Figure1).By following those guidelines we can have a safe,non–redundant,and efficient concurrency control.We definespecific guidelines for each kind of class of the architecturepresented in Section2.The guidelines prevent naive con-trols such as synchronizing all the system access methods(facade’s methods)or implementing database transactions for all those methods.We also indicate the most commonlyapplied concurrency control techniques according to our ex-perience acquired through the implementation and analysis of systems that use the same software architecture consid-ered here.General guidelines,based in basic principles of concur-rency control,are needed to avoid concurrent executions ofnon–atomic methods and methods that read the attributes modified by the non-atomic ones.Examples of this kind ofmethod are the ones that access or attributes, since the Java specification[10]does not guarantee atomicassignments to these types.To avoid such concurrent execu-tions we can use the Java method modifier, which serializes concurrent executions of modified methods in the same object.3.1.Business Basic ClassesWe start to define the specific guidelines with the busi-ness basic classes(see Figure1),which represent system basic objects such as customers and accounts.First of all, we must identify which basic objects might be concurrently accessed.Identifying Concurrent AccessThe data collections classes(see Figure1)determine if an object may be concurrently accessed because these classes are responsible for storing and retrieving basic objects. Usually,persistent collections that use relational databases create a new instance,with the data retrieved from the database,for each request to search for an object.Therefore,if two threads,for example,try to retrieve ac-counts with the same number,the threads will get references to distinct copies of the object stored in the database.This avoids concurrent access on any instance,since we assume that the concurrency environment allows two or more clients to access the system,but each user access it sequentially.An alternative to this approach for implementing data collections is to use object caching to guarantee that there will be a single object in memory for each entity stored in the database.This approach is used by some relational and object–oriented database access APIs[16,17,7]to prevent inconsistencies that might happen,for example,in the case of a concurrent update of two copies of the same account. In this case,concurrent requests to retrieve an account with the same number will receive a same reference to the object stored in the cache.This allows the concurrent access to basic objects,which is controlled by basic guideline men-tioned in the beginning of the section.Introducing Concurrency ControlAfter identifying the basic objects that might be concur-rently accessed,we must apply the general guidelines to the corresponding classes.In the classes whose objects are not concurrently accessed we must still analyze situa-tions where concurrent updates of copies of the same object should not be allowed.For example,an class has methods such as and,which update the attribute based on its old value.Concurrent up-dates of two copies of the same account might take system to an inconsistent state.Consider a possible execution where the balances of copies of the same are concurrently modified, where two threads concurrently execute three operations:to request an account to the data collection,to deposit a value in the retrieved object,and to update the object in the data collection.After executing,the account’s infor-mation may be inconsistent because each thread works with a different copy of the same object,and the second copy to be updated overwrites thefirst one.In order to avoid this problem with concurrent updates of object copies,our guideline suggests the implementation of an update control for each persistent object.This can be done using a timestamp–based technique that adds version information to those objects.Note that this technique is not an implementation of a database algorithm such as times-tamp ordering[12].The idea is to allow object updating just if there is not a newer version of it stored in the database. Otherwise,the operation must be restarted.3.2.Data Collection ClassesThe data collections classes(see Figure1)are responsi-ble to store and retrieve basic objects.They implement the business–data interfaces,which are abstractions of the sys-tem’s data management.These interfaces allow us to easily extend the system changing the data management mecha-nism,by providing implementations of the business–data interfaces to the respectively data management mechanism.In the persistent data collections we can alsofind concur-rency problems when an object is inserted,updated,or re-moved from the database.In these cases we must guarantee that database features are properly used;we must include, update,or remove an object inside a database transaction. In this way,we can assume that great part of the concur-rency control,regarding to data update,is implemented by the database.Considering this,we must guarantee that the methods of the facade are atomic regarding database access. We can do this by implementing database accesses with a single SQL command,or by implementing transactions in the facade’s methods,using the persistence mechanism in-terface services.To guarantee the atomicity of the data col-lection methods we must follow the following steps: Identify data collection methods that directly or indi-rectly execute two or more SQL commands;Identify business collection methods that call the data collection methods identified in the last step;Identify facade methods that call business collection methods identified in the last step;The facade methods identified in the last step must use the persistence mechanism interface meth-ods,andto implement a transaction on its body.For example,in the following method of theclass,the underlined pieces of code are responsible for the transaction mechanism implementation.public class Bankprivate AccountsRecords accounts;private PersistenceMechanismInterface pm;public void update(Account account) trypm.beginTransaction();catch(DBTransactionException e)pm.rollbackTransaction();ing.The tests execute these three operations in different ver-sions of the system,each one implementing different con-currency controls.Wefirst compare the following versions: No control:system without concurrency control;Synchronized facade:all facade class methods syn-chronized;Facade with transactions:all facade class methods im-plementing transactions;Suggested Control:applying the defined guidelines, with the concurrency manager in the business collec-tion and the timestamp for the basic class.Only the synchronized facade approach and the one that applies our guidelines guarantee system correctness,if ap-plied separately.In fact,the former just guarantees system correctness if two copies of a basic object can be concur-rently updated,otherwise the approach is not safety.The no control approach is used as a reference to measure the controls impact.The second test measures the impact of the timestamp mechanism,so we compare the following system versions: No control:system without concurrency control;Timestamp:timestamp mechanism implemented for the basic class;We also analyze our alternative for method synchroniza-tion,comparing the following system versions:Synchronization in the Business Collection:business collection method synchronized;Concurrency Manager in the Business Collection: business collection method using the Concur-rency Manager pattern;For each of the different versions we also analyze varia-tions in the controlled methods.Thus,we can measure the impact of different concurrency controls in different types of systems represented by those variations.For example, variations on method execution time were implemented by including a loop that increases the execution time in approx-imately100%,which we called heavyweight methods.An-other variation in the tests is an increasing in the system workload.We tested the system with workloads between3 and600threads concurrently accessing the system.There-fore we could simulate a situation of extreme concurrency, hardly found in access rates of real systems.For instance, we collected numbers for a considerably used web system that has a reasonable access rate of more than400users (not hits)accessing the system in an hour,whereas our ex-periments execute in few seconds.In our tests there were 12available connections with the persistence mechanism, which were shared between the threads,without concurrent access to them.4.2.Performance AnalysisThe following paragraphs summarize the tests with the different variations such as system workload and method weight.General Approaches for Concurrency ControlFigure2presents a bar chart that compares the no concur-rency control system with the approach that synchronizes all facade methods,the one that implements transactions in all facade methods,and the approach that applies our guide-lines.Figure2.Impact of concurrency controls.The chart shows that synchronizing all facade methods is a very expensive approach,increasing the execution time up to120%.We can notice a significant overhead,more than50%,when implementing transaction for all facade methods.This is a motivation to apply our guidelines for concurrency control,because it indicates exactly which fa-cade methods must implement transactions.We can con-clude that our guidelines impact is small,less than10%,if compared with the others approaches.However,this is a necessary impact to guarantee the system safety.This chart shows data observed by executing lightweight method.In systems with heavyweight methods the exe-cution time increases50%,but the difference of execution time between the approaches is lower.TimestampSimilar to the results of the previous test,we can see in Fig-ure3the performance impact of the timestamp mechanism. The impact with lightweight methods is smaller then with heavyweight methods.This occurs because of the number of connections,which restricts the number of concurrent re-quests to the persistence mechanism.If the methods of the data collection are heavier they take more time to executeand keep the connections for a bigger time,delaying the ex-ecution of others threads.In these tests we had 12available connections with the persistence mechanism.Although a considerable impact in the case of heavyweight methods,this is a necessary control to guarantee system correctness.However,increasing the number of available connections adding more connections might decrease thisimpact.Figure 3.Timestamp mechanism impact.Concurrency ManagerThe last test compares the concurrency manager design pat-tern and the modifier performance to con-trol the concurrency in the business collection methods.We considered another variation besides the system workload and methods weight:some of the tests lead to race condi-tion,on the same basic object,allowing the evaluation of our solution according to this aspect.This variation is im-plemented creating threads that try to insert,to update,and to retrieve customers with the same code.We considered this variation because it suggests the use of different alter-natives in specific situations,since the concurrency manager uses this information (methods semantics)to synchronize the threads only when it is necessary.Figure 4shows the negative performance impact caused by the modifier versus compared with the concurrency manager.When few users are accessing the system concurrently the modified is slightly worst (up to 3%)than concurrency manager.For systems that expect this access rate we suggest the adop-tion of themodifier solution,since it is sim-pler to implement and to maintain.For systems that expect higher access rates,we suggest the use of the concurrency manager,which offer a performance going of up to 20%.This gain is bigger (up to 30%)when there is no race con-dition over the same object,which is typically the case for systems like the one we analyzed.In the tests with heavy-weight methods the control impact of themodifier is less than with lightweight methods,but still rel-evant (10%to20%).Figure 4.Concurrency Manager versus.5.ConclusionsContrasting with general well–know [11,14]approaches for concurrency control,we defined guidelines for develop-ing web–based systems tailored to a specific architecture widely used to develop this kind of system.We also as-sume the use of relational databases,which are also widely used for implementing web–based information systems.Our guidelines use the concurrency control mechanism of both Java [10],the programming language,and relational databases.However,those approaches [11,14]cover a big-ger portion of the systems concurrency problems,since it is not tailored to a specific architecture for web–based systems using relational databases,as our guidelines.The main point of the guidelines is to guarantee sys-tem correctness without redundant concurrency control,both increasing performance and guaranteeing safety.The database management systems (DBMS)deal with a big por-tion of the system concurrency control reducing the need for programming language concurrency control features.This is the case for basic classes,where language features are only necessary if their objects are concurrently accessed.According to our experience this is not the case for many web–based systems developed with JDBC.However,the DBMS do not solve all problems related to concurrency control.Therefore we need to know where to use program-ming language features in order to avoid redundant controls and their negative performance impact.We have shown that those problems can be solved through our guidelines for concurrency control,preventing losses from 10%to 110%in the execution time,when compared with naive solutions such as synchronizing facade methods.The concern about avoiding unnecessary concurrent con-trol is topic of many works [3,1,6].One of them [3]uses global data flow analyses to identify what objects with synchronized methods cannot be concurrently accessed in a specific program.An advantage of this approach is that it is completely automatized.In fact,a big portion of our guidelines can also be automatized.Our approach differs from this one because we guide the system implementationto avoid unnecessary synchronization,also giving guide-lines to control race conditions added by business polices. However,contrasting with our approach,this related work doesn’t guarantee system safety.It guarantees just the safety of the optimizations made by the analyses,therefore, the system implementation must guarantee safety before ap-plying the analyses(optimizations).We might say that our guidelines and this approach are complementary,since the guidelines can be applied to guarantee the system safety be-fore execute the dataflow analyses and the optimization.In this paper we analyze some alternatives to solve con-currency problems showing,in general,that the concur-rency manager is more efficient than themodifier.Moreover,we show the negative impact of the widespread use of the method qualifier,as well as of the unnecessary implementation of transactions in facade methods.The experiments also allow us to state that the impact of the guidelines application in a system is relatively small;mainly when comparing with the other ap-proaches(see Section4).Another advantage of our pro-posal being based on specific software architecture,is al-lowing the exact definition and application of the guide-lines,giving better support to programmers.Although spe-cific,the software architecture has been and can be used to implement a wide range of web–based information system. Development productivity is increased because the guide-lines precisely indicate the points where concurrency con-trol code must be applied,identifying classes and situations passive of control,and which mechanism should be used to control such problem.We applied our guidelines in two real web–based infor-mation systems in order to validate them.Thefirst sys-tem was already implemented and running,and we used the guidelines as a mechanism for checking whether the sys-tem controls concurrency correctly.This helped us to val-idate the guidelines,since some concurrency control that our guidelines define was used in those systems,such as us-ing transactions only when it is necessary.We also found some naive controls,which could be avoided if our guide-lines were used.In the second system,which is another implementation of the application implemented by thefirst system,the guidelines were applied during the implemen-tation phase.We made this to analyze the impact of using the guidelines in the implementation time.In this case the guidelines were responsible to10%of the implementation time,which shows a small impact of them.References[1]O.Agesen,D.Detlefs,A.Garthwaite,R.Knippel,Y.S.Ramakrishna,and D.White.An efficient meta-lock for implementing ubiquitous synchronization.In Proceedings of the1999ACM SIGPLAN conference on Object-orientedprogramming,systems,languages,and applications,pages 207–222,November1999.[2]I.M.Author.Some related article I wrote.Some Fine Jour-nal,99(7):1–100,January1999.[3]J.Bogda and U.H¨o lzle.Removing unnecessary synchro-nization in Java.In Proceedings of the1999ACM SIGPLAN conference on Object-oriented programming,systems,lan-guages,and applications,pages35–46,November1999. [4]G.Booch,I.Jacobson,and J.Rumbaugh.Unified ModelingLanguage–User’s Guide.Addison–Wesley,1999.[5] F.Buschmann,R.Meunier,H.Rohnert,P.Sommerlad,andM.Stal.A System of Patterns:Pattern–Oriented Software Architecture.John Wiley&Sons,1996.[6]J.-D.Choi,M.Gupta,M.Serrano,V.C.Sreedhar,andS.Midkiff.Escape analysis for Java.In Proceedings of the 1999ACM SIGPLAN conference on Object-oriented pro-gramming,systems,languages,and applications,pages1–19.ACM,November1999.[7]O.Design.Pse pro for java api user guide,2001.Avaiable at /i/documentation/doc/-psepro/pse-java/doc/pdf/pseug.pdf.[8] A.N.Expert.A Book He Wrote.His Publisher,Erewhon,NC,1999.[9] E.Gamma,R.Helm,R.Johnson,and J.Vlissides.DesignPatterns:Elements of Reusable Object–Oriented Software.Addison–Wesley,1994.[10]J.Gosling,B.Joy,G.Steele,and G.Bracha.The Java Lan-guage Specification.Addison–Wesley,second edition,2000.[11] D.Lea.Concurrent Programming in Java.Addison-Wesley,second edition,1999.[12]V.Li.Performance models of timestamp-ordering concur-rency control algorithms in distributed databases.IEEE Transactions on Computers,36(9):1041–1051,1987. [13]T.Massoni,V.Alves,S.Soares,and P.Borba.PDC:Per-sistent Data Collections pattern.In First Latin American Conference on Pattern Languages Programming—Sugar-LoafPLoP,Rio de Janeiro,Brazil,3th–5th October2001.To appear in UERJ Magazine:Special Issue on Software Pat-terns.[14] D.Schmidt,M.Stal,H.Rohnert,and F.Buschmann.Pattern-Oriented Software Architecture,Vol.2:Patterns for Concurrent and Networked Objects.Wiley&Sons,2000.[15]S.Soares and P.Borba.Concurrency Manager.In First LatinAmerican Conference on Pattern Languages Programming —SugarLoafPLoP,Rio de Janeiro,Brazil,3th–5th October 2001.To appear in UERJ Magazine:Special Issue on Soft-ware Patterns.[16] A.Software.O2technology user manual:Java relationalbinding.Version2.0,July1997.[17]Sun Microsystems.The Enterprise Java Beans Specification,October2000.Avaiable at /products/-ejb/docs.html.。