|
305 | 305 | output ="false" |
306 | 306 | > |
307 | 307 | <cfscript> |
308 | | - var iterator = getClassLoadPaths().iterator(); |
309 | | - var file = 0; |
310 | | - var classLoader = 0; |
311 | | - var networkClassLoaderClass = 0; |
312 | | - var networkClassLoaderProxy = 0; |
313 | | - |
314 | | - networkClassLoaderClass = getServerURLClassLoader().loadClass( |
315 | | - "com.compoundtheory.classloader.NetworkClassLoader" |
316 | | - ); |
317 | | - |
318 | | - networkClassLoaderProxy = createJavaProxy( networkClassLoaderClass ); |
319 | | - |
320 | | - if ( isObject( getParentClassLoader() ) ) { |
321 | | - classLoader = networkClassLoaderProxy.init( getParentClassLoader() ); |
322 | | - } else { |
323 | | - classLoader = networkClassLoaderProxy.init(); |
| 308 | + var networkClassLoaderKey = instance.static.uuid & "." & getVersion() & ".networkclassloader"; |
| 309 | + |
| 310 | + // Reuse existing NetworkClassLoader if already cached in server scope |
| 311 | + if ( structKeyExists( server, networkClassLoaderKey ) ) { |
| 312 | + setURLClassLoader( server[ networkClassLoaderKey ] ); |
| 313 | + return; |
324 | 314 | } |
325 | 315 |
|
326 | | - while ( iterator.hasNext() ) { |
327 | | - file = createObject( "java", "java.io.File" ).init( iterator.next() ); |
328 | | - if ( NOT file.exists() ) { |
329 | | - throwException( |
330 | | - "javaloader.PathNotFoundException", |
331 | | - "The path you have specified could not be found", |
332 | | - file.getAbsolutePath() & " does not exist" |
333 | | - ); |
| 316 | + lock name="javaloader.networkclassloader.load" throwontimeout="true" timeout="60" { |
| 317 | + // Double-check inside lock |
| 318 | + if ( structKeyExists( server, networkClassLoaderKey ) ) { |
| 319 | + setURLClassLoader( server[ networkClassLoaderKey ] ); |
| 320 | + return; |
334 | 321 | } |
335 | 322 |
|
336 | | - classLoader.addUrl( file.toURL() ); |
337 | | - } |
| 323 | + var iterator = getClassLoadPaths().iterator(); |
| 324 | + var file = 0; |
| 325 | + var classLoader = 0; |
| 326 | + var networkClassLoaderClass = 0; |
| 327 | + var networkClassLoaderProxy = 0; |
| 328 | + |
| 329 | + networkClassLoaderClass = getServerURLClassLoader().loadClass( |
| 330 | + "com.compoundtheory.classloader.NetworkClassLoader" |
| 331 | + ); |
| 332 | + |
| 333 | + networkClassLoaderProxy = createJavaProxy( networkClassLoaderClass ); |
| 334 | + |
| 335 | + if ( isObject( getParentClassLoader() ) ) { |
| 336 | + classLoader = networkClassLoaderProxy.init( getParentClassLoader() ); |
| 337 | + } else { |
| 338 | + classLoader = networkClassLoaderProxy.init(); |
| 339 | + } |
338 | 340 |
|
339 | | - setURLClassLoader( classLoader ); |
| 341 | + while ( iterator.hasNext() ) { |
| 342 | + file = createObject( "java", "java.io.File" ).init( iterator.next() ); |
| 343 | + if ( NOT file.exists() ) { |
| 344 | + throwException( |
| 345 | + "javaloader.PathNotFoundException", |
| 346 | + "The path you have specified could not be found", |
| 347 | + file.getAbsolutePath() & " does not exist" |
| 348 | + ); |
| 349 | + } |
| 350 | + classLoader.addUrl( file.toURL() ); |
| 351 | + } |
| 352 | + |
| 353 | + server[ networkClassLoaderKey ] = classLoader; |
| 354 | + setURLClassLoader( classLoader ); |
| 355 | + } |
340 | 356 | </cfscript> |
341 | 357 | </cffunction> |
342 | 358 |
|
|
0 commit comments