是ArrayDescriptor线程安全吗?

时间:2013-03-29 15:13:42

标签: java oracle jdbc thread-safety

是oracle.sql.ArrayDescriptor threadsafe的实例吗?

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

2 个答案:

答案 0 :(得分: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 {};
}

因此,存在这些非最终变量可能会被访问​​同一oracle.sql.ArrayDescriptor类对象的各种线程无法预测地改变的可能性。所以我仍然认为它不是Thread-safe

答案 1 :(得分:1)

猜猜是什么?源代码似乎在人们可以找到的正常位置中不可用,因此除了询问Oracle支持之外,没有办法确定... ...

基于API设计,可以是线程安全的。没有setter,看起来这个类从客户端的角度来看是不可变的。您可以通过将javap指向字节码文件并查看实例变量是否都声明为final来确认这一点。

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