001// Copyright 2009, 2011 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.ioc.internal.util; 016 017import java.util.concurrent.locks.Lock; 018import java.util.concurrent.locks.ReentrantLock; 019 020/** 021 * Internal utilities for identifying the JDK version, used in the rare cases 022 * that we are patching around JDK bugs. 023 */ 024public class JDKUtils 025{ 026 /** 027 * Is the running JVM JDK 1.5? 028 */ 029 public static final boolean JDK_1_5 = isVersion("1.5"); 030 031 private static boolean isVersion(String versionId) 032 { 033 return System.getProperty("java.specification.version").equals(versionId); 034 } 035 036 /** 037 * Returns a {@link ReentrantLock} used to serialize access to the construction of a thread local; this is only needed under JDK 1.5 (due to a bug in the JDK); 038 * for other JDKs, a {@link DummyLock} is returned. 039 * 040 * @return lock to use when creating 041 * @since 5.3 042 * @deprecated Deprecated in 5.4 with no replacement. 043 */ 044 public static Lock createLockForThreadLocalCreation() 045 { 046 return JDK_1_5 ? new ReentrantLock() : new DummyLock(); 047 } 048}