Runtime versus compile time
Java typically has a flat classpath, whether at compile time or at runtime. In other words, applications normally have full visibility to any class that's found on the classpath, regardless of the order of entries in the classpath (assuming that there are no overlaps, at least; otherwise, first one wins). This enables the functionality of dynamic linking in Java; a class loaded from the front of the classpath need not have resolved all references to the classes that may be towards the rear of the classpath until they're actually required.
This is frequently used when working against a set of interfaces to which the implementation isn't known about until runtime. For example, an SQL utility can be compiled against the generic JDBC package, but at runtime (and with an additional piece of configuration information) can instantiate the correct JDBC driver. This is typically achieved through the name of a class (which implements a pre-defined factory interface or abstract class) being supplied to a Class.forName
lookup at runtime. If the specified class doesn't exist (or can't be loaded for any other reason) an error is generated.
It's therefore quite likely that the compile time classpath is (subtly) different from the runtime classpath for a module. Further, each module is often compiled in isolation (module A may be compiled against module C 1.1, and module B may be compiled against module C 1.2) but then combined at runtime in a single path (and in this case, either arbitrarily choosing version 1.1 or 1.2 of module C). This leads quickly to Dependency Hell, especially when it is the transitive closure of these dependencies which forms the runtime classpath. Build systems like Maven and Ivy make modularity visible to developers, if not end users.
Java has an under appreciated feature called ClassLoaders which allow the runtime path to be more segmented. Typically, all classes are loaded from the system ClassLoader; however, some systems partition their runtime space with different ClassLoaders. A good example is Tomcat (or other Servlet engines) which typically have a one ClassLoader-per-WebApp. This allows a WebApp to function normally but not see (accidentally or otherwise) classes defined by other WebApps in the same JVM.
The way this works is that each WebApp loads classes from its own ClassLoader, so that a (local) WebApp's implementation doesn't load classes which conflict with another WebApp's implementation. The requirement is, for any ClassLoader chain, that the class spaces be consistent; this means you can have two Util.class
es loaded from two separate ClassLoaders in your VM at one time, provided that these ClassLoaders aren't visible to one another. (It's also what gives the Servlet engine its ability to redeploy changes without a restart; by throwing a ClassLoader away, you throw away references to its classes as well, making the old version eligible for garbage collection – this then allows the Servlet engine to create a new ClassLoader and re-load the new versions of the classes in at runtime.)
InfoQ
分享到:
相关推荐
### 感应电机与永磁电机对比分析 在当今及未来的电机市场中,对于功率密度、运行效率、可靠性、可变速度操作以及低成本等方面的需求日益增加。永磁(PM)电机因其高效率、高可靠性及更高的功率密度(单位质量或体积...
Work through practical challenges and use cases of real-time analytics versus batch analytics Develop real-word use cases for processing and analyzing data in real-time using the programming paradigm ...
本文件用于绘制miss rate versus false positives per image(FPPI)曲线 使用方法参考:https://blog.csdn.net/weixin_38705903/article/details/109654157
In practice, time sharing methods such as Time Division Multiple Access (TDMA) are often exploited to create orthogonal connections. TDMA schemes however are inflexible and not suitable for ...
versus ( 1 , '==' , 2 ) ; //=> false versus ( 1 , '===' , 2 ) ; //=> false versus ( 1 , '!=' , 2 ) ; //=> true versus ( 1 , '!==' , 2 ) ; //=> true versus ( 1 , '<' , 2 ) ; //=> true versus ( 1 , ...
BertsimasD,DunningI,LubinM.Reformulationsvs.cuttingplanesforrobust optimization: acomputationalandmachinelearningperspective.unpub- lished workingpaperavailableonlineatoptimization-online.org.Apr2014
Science versus naturePPT教案.pptx
Oral dabigatran versus enoxaparin for thromboprophylaxisafter primary total hip
Graph-Cuts与Level-Sets是计算机视觉和图像处理领域中的两种关键算法,它们在解决分割问题上具有重要的应用。在ECCV06(欧洲计算机视觉会议2006)的教程中,这部分内容深入探讨了这两种技术的原理、优势和局限性。...
"Modus Versus"在IT领域中可能是指一个特定的项目、框架或者工具,但具体信息较少,只能根据标签“CSS”来进行关联性解读。CSS(Cascading Style Sheets)是一种样式表语言,用于描述HTML或XML(包括如SVG、MathML等...
《JavaScript中的Versus AI Duel Game源代码解析》 在当今的Web开发领域,JavaScript作为最常用的前端编程语言,被广泛应用于各种动态交互效果和游戏开发。本篇文章将深入探讨一个基于JavaScript实现的“Versus AI ...
标题与描述:“Pi calculus versus Petri nets”,这一主题聚焦于两种在信息技术领域内,特别是流程感知信息系统(Process-Aware Information Systems, PAISs)中应用广泛的建模工具之间的比较:Pi calculus(π演算...
Philosophy Doctorate versus Professional Doctorate,仇志成,,Over the last decade, post-graduate education in Australia has been on the wheel of change. There has been a major increase in the numbers...
总的来说,"Squanderville versus Thriftville"不仅是对个人理财的教诲,也是对国家经济政策的深刻反思。通过理解巴菲特的寓言,我们可以更好地理解消费、储蓄、债务和经济增长之间的复杂关系,从而做出更明智的决策...
### CC11xx Sensitivity Versus Frequency Offset and Crystal Accuracy #### 概述 设计文档DN005SWRA122C(以下简称“该文档”)深入探讨了CC11xx系列芯片(包括CC1100、CC1100E、CC1101、CC1110、CC1111等)在...
The SAS Versus R Debate in Industry and Academia
Business Use Cases versus System Use Cases.mht
「安全方案」ICS Risk Management Approaches:Vulnerability versus Threat versus Engineering, and What Works Best for You - 防火墙 web安全 APT攻击 web安全 安全管理 无线安全
标题中的"debs_kafka_versus_rabbitmq"表明这是一个关于比较Apache Kafka与RabbitMQ的讨论。这两个都是流行的消息中间件,主要用于在分布式系统中处理和传递消息。在这个压缩包中,我们有一个名为"debs_kafka_versus...
This application note includes an object versus range table to list the detection range capabilities of TI's mmWave radar sensors. The method used for data collection is reported and the data for the ...