1

oracle.sql.ArrayDescriptor 的实例是线程安全的吗?

此类的 API http://docs.oracle.com/cd/E16338_01/appdev.112/e13995/oracle/sql/ArrayDescriptor.html没有提及任何关于线程安全的内容。

4

2 回答 2

2

在类上运行javap命令oracle.sql.ArrayDescriptor..可以观察到oracle.sql.ArrayDescriptor类的公共方法都没有同步。以下是 javap 的说明:

E:\users>javap oracle.sql.ArrayDescriptor
Compiled from "ArrayDescriptor.java"
public class oracle.sql.ArrayDescriptor extends oracle.sql.TypeDescriptor implem
ents java.io.Serializable{
    public static final int TYPE_VARRAY;
    public static final int TYPE_NESTED_TABLE;
    public static final int CACHE_NONE;
    public static final int CACHE_ALL;
    public static final int CACHE_LAST;
    static final long serialVersionUID;
    public static final boolean TRACE;
    public static final boolean PRIVATE_TRACE;
    public static final java.lang.String BUILD_DATE;
    public static oracle.sql.ArrayDescriptor createDescriptor(java.lang.String, java.sql.Connection) throws java.sql.SQLException;
    public static oracle.sql.ArrayDescriptor createDescriptor(java.lang.String, java.sql.Connection, boolean, boolean) throws java.sql.SQLException;
    public static oracle.sql.ArrayDescriptor createDescriptor(oracle.sql.SQLName,  java.sql.Connection) throws java.sql.SQLException;
    public static oracle.sql.ArrayDescriptor createDescriptor(oracle.sql.SQLName, java.sql.Connection, boolean, boolean) throws java.sql.SQLException;
    public static oracle.sql.ArrayDescriptor createDescriptor(oracle.jdbc.oracore.OracleTypeCOLLECTION) throws java.sql.SQLException;
    public oracle.sql.ArrayDescriptor(java.lang.String, java.sql.Connection) throws java.sql.SQLException;
    public oracle.sql.ArrayDescriptor(oracle.sql.SQLName, java.sql.Connection) throws java.sql.SQLException;
    public oracle.sql.ArrayDescriptor(oracle.sql.SQLName, oracle.jdbc.oracore.OracleTypeCOLLECTION, java.sql.Connection) throws java.sql.SQLException;
    public oracle.sql.ArrayDescriptor(oracle.jdbc.oracore.OracleTypeCOLLECTION, java.sql.Connection) throws java.sql.SQLException;
    static oracle.sql.ArrayDescriptor createDescriptor(oracle.sql.SQLName, byte[], int, byte[], byte[], oracle.jdbc.internal.OracleConnection, byte[]) throws java.sql.SQLException;
    public int getBaseType() throws java.sql.SQLException;
    public java.lang.String getBaseName() throws java.sql.SQLException;
    public oracle.jdbc.oracore.OracleTypeCOLLECTION getOracleTypeCOLLECTION();
    public int getArrayType() throws java.sql.SQLException;
    public long getMaxLength() throws java.sql.SQLException;
    public java.lang.String descType()  throws java.sql.SQLException;
    java.lang.String descType(java.lang.StringBuffer, int) throws java.sql.SQLException;
    int toLength(oracle.sql.ARRAY) throws java.sql.SQLException;
    byte[] toBytes(oracle.sql.ARRAY, boolean) throws java.sql.SQLException;
    oracle.sql.Datum[] toOracleArray(oracle.sql.ARRAY, long, int, boolean) throws java.sql.SQLException;
    java.lang.Object[] toJavaArray(oracle.sql.ARRAY, long, int, java.util.Map, boolean) throws java.sql.SQLException;
    public java.sql.ResultSet toResultSet(oracle.sql.ARRAY, long, int, java.util.Map, boolean) throws java.sql.SQLException;
    public java.sql.ResultSet toResultSet(oracle.sql.Datum[], long, int, java.util.Map) throws java.sql.SQLException;
    public java.sql.ResultSet toResultSetFromLocator(byte[], long, int, java.util.Map) throws java.sql.SQLException;
    public java.sql.ResultSet toResultSetFromImage(oracle.sql.ARRAY, long, int, java.util.Map) throws java.sql.SQLException;
    public static java.lang.Object[] makeJavaArray(int, int) throws java.sql.SQLException;
    oracle.sql.Datum[] toOracleArray(java.lang.Object, long, int) throws java.sql.SQLException;
    java.lang.Object toNumericArray(oracle.sql.ARRAY, long, int, int, boolean) throws java.sql.SQLException;
    public int getTypeCode() throws java.sql.SQLException;
    public byte[] toBytes(oracle.sql.Datum[]) throws java.sql.SQLException;
    public byte[] toBytes(java.lang.Object[]) throws java.sql.SQLException;
    public int length(byte[]) throws java.sql.SQLException;
    public oracle.sql.Datum[] toArray(byte[]) throws java.sql.SQLException;
    public oracle.sql.Datum[] toArray(java.lang.Object) throws java.sql.SQLException;
    public java.sql.ResultSet toResultSet(byte[], java.util.Map) throws java.sql.SQLException;
    public java.sql.ResultSet toResultSet(byte[], long, int, java.util.Map) throws java.sql.SQLException;
    public static int getCacheStyle(oracle.sql.ARRAY) throws java.sql.SQLException;
    static {};
}

因此,假设它不是线程安全的,您应该继续使用此类。

更新
根据您的要求,因为该类的所有私有和公共变量都是最终的,因此实例的内部状态不会被其方法改变。但oracle.sql.ArrayDescriptor也继承oracle.sql.TypeDescriptor了其中包含非最终变量,如下所示:

E:\users>javap -private oracle.sql.TypeDescriptor
Compiled from "TypeDescriptor.java"
public abstract class oracle.sql.TypeDescriptor extends java.lang.Object implements java.io.Serializable{
    public static boolean DEBUG_SERIALIZATION;
    static final long serialVersionUID;
    oracle.sql.SQLName sqlName;
    oracle.jdbc.oracore.OracleNamedType pickler;
    transient oracle.jdbc.internal.OracleConnection connection;
    private static final java.lang.String _Copyright_2004_Oracle_All_Rights_Reserved_;
    public static final boolean TRACE;
    public static final boolean PRIVATE_TRACE;
    public static final java.lang.String BUILD_DATE;
    protected oracle.sql.TypeDescriptor();
    protected oracle.sql.TypeDescriptor(java.lang.String, java.sql.Connection)throws java.sql.SQLException;
    protected oracle.sql.TypeDescriptor(oracle.sql.SQLName, java.sql.Connection)throws java.sql.SQLException;
    protected oracle.sql.TypeDescriptor(oracle.sql.SQLName, oracle.jdbc.oracore.OracleTypeADT, java.sql.Connection)throws java.sql.SQLException;
    protected oracle.sql.TypeDescriptor(oracle.jdbc.oracore.OracleTypeADT, java.sql.Connection)throws java.sql.SQLException;
    public synchronized java.lang.String getName() throws java.sql.SQLException;
    public synchronized oracle.sql.SQLName getSQLName() throws java.sql.SQLException;
    void initSQLName()       throws java.sql.SQLException;
    public java.lang.String getSchemaName()       throws java.sql.SQLException;
    public java.lang.String getTypeName()       throws java.sql.SQLException;
    public oracle.jdbc.oracore.OracleNamedType getPickler();
    public oracle.jdbc.internal.OracleConnection getInternalConnection();
    public void setPhysicalConnectionOf(java.sql.Connection);
    public abstract int getTypeCode()       throws java.sql.SQLException;
    public static oracle.sql.TypeDescriptor getTypeDescriptor(java.lang.String,oracle.jdbc.OracleConnection) throws java.sql.SQLException;
    public static oracle.sql.TypeDescriptor getTypeDescriptor(java.lang.String,oracle.jdbc.OracleConnection, byte[], long) throws java.sql.SQLException;
    public boolean isInHierarchyOf(java.lang.String) throws java.sql.SQLException;
    private void writeObject(java.io.ObjectOutputStream)throws java.io.IOException;
    private void readObject(java.io.ObjectInputStream)throws java.io.IOException, java.lang.ClassNotFoundException;
    public void setConnection(java.sql.Connection) throws java.sql.SQLException;
    public static java.lang.String getSubtypeName(oracle.jdbc.OracleConnection,byte[], long) throws java.sql.SQLException;
    public void initMetadataRecursively()       throws java.sql.SQLException;
    public void initNamesRecursively()       throws java.sql.SQLException;
    public void fixupConnection(oracle.jdbc.internal.OracleConnection) throws java.sql.SQLException;
    public java.lang.String toXMLString()       throws java.sql.SQLException;
    public void printXML(java.io.PrintStream)       throws java.sql.SQLException;
    void printXML(java.io.PrintWriter, int)       throws java.sql.SQLException;
    void printXMLHeader(java.io.PrintWriter)       throws java.sql.SQLException;
    static {};
}

Hence there are the possibilities that these non-final variables would changed unpredictably by various threads accessing the same object of oracle.sql.ArrayDescriptor class. So I still think that it is not Thread-safe.

于 2013-03-29T15:39:50.600 回答
1

你猜怎么了?源代码似乎无法在人们可以找到的正常地方获得,因此无法确定...除了询问 Oracle 支持。

基于 API 设计,它可以是线程安全的。没有设置器,从客户端的角度来看,该类似乎是不可变的。您可以通过指向javap字节码文件并查看实例变量是否都声明为final.

但是,如果您无法得到确认,安全的方法是假设该类不是线程安全的。

于 2013-03-29T15:27:23.197 回答