Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion src/main/java/com/ibm/as400/access/AS400.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public class AS400 implements Serializable, AutoCloseable
private static boolean defaultMustUseSuppliedProfile_ = false;
// Default setting for threadUsed property.
private static boolean defaultThreadUsed_ = true;
// Default setting for virtualThreads property.
private static boolean defaultVirtualThreads_ = false;

boolean skipSignonServer_ = false;
public String currentLib_ = "*CURUSR";
Expand Down Expand Up @@ -351,6 +353,8 @@ public class AS400 implements Serializable, AutoCloseable
private boolean mustUseSuppliedProfile_ = defaultMustUseSuppliedProfile_;
// Flag that indicates if we use threads in communication with the host servers.
private boolean threadUsed_ = defaultThreadUsed_;
// Flag that indicates if we use virtual threads
private boolean virtualThreads_ = defaultVirtualThreads_;
// Locale object to use for determining NLV.
private Locale locale_ = Locale.getDefault();
// The NLV set or determined from the locale.
Expand Down Expand Up @@ -1082,6 +1086,7 @@ public AS400(AS400 system)
mustUseNetSockets_ = system.mustUseNetSockets_;
mustUseSuppliedProfile_ = system.mustUseSuppliedProfile_;
threadUsed_ = system.threadUsed_;
virtualThreads_ = system.virtualThreads_;
locale_ = system.locale_;
nlv_ = system.nlv_;
socketProperties_.copyValues(system.socketProperties_);
Expand Down Expand Up @@ -1813,7 +1818,7 @@ private synchronized void chooseImpl()

if (!propertiesFrozen_)
{
impl_.setState(useSSLConnection_, canUseNativeOptimizations(), threadUsed_, ccsid_, nlv_,
impl_.setState(useSSLConnection_, canUseNativeOptimizations(), threadUsed_, virtualThreads_, ccsid_, nlv_,
socketProperties_, ddmRDB_, mustUseNetSockets_, mustUseSuppliedProfile_, mustAddLanguageLibrary_);
propertiesFrozen_ = true;
}
Expand Down Expand Up @@ -3645,6 +3650,18 @@ public boolean isThreadUsed()
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Checking if thread is used:", threadUsed_);
return threadUsed_;
}

/**
* Indicates whether threads are used in communication with the host servers.
*
* @return true if threads are used; false otherwise.
**/
public boolean isVirtualThreads()
{
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Checking if virtual threads are used:", virtualThreads_);
return virtualThreads_;
}


/**
* Indicates if the default user should be used by this object. If the default user is not used and a user ID was
Expand Down Expand Up @@ -5362,6 +5379,44 @@ public void setThreadUsed(boolean useThreads) throws PropertyVetoException
propertyChangeListeners_.firePropertyChange("threadUsed", oldValue, newValue);
}
}

/**
* Sets whether the IBM Toolbox for Java uses virtual threads in communication with the host servers. The default is false.
* The virtual thread used property cannot be changed once a connection to the system has been established.
*
* <p>
* Note: This property may also be set by specifying 'true' or 'false' in Java system property
* <tt>com.ibm.as400.access.AS400.virtualThreads</tt>
*
* @param virtualThreads true to use virtual threads; false otherwise.
* @exception ExtendedIllegalStateException If a connection has already been made.
* @exception PropertyVetoException If any of the registered listeners vetos the property change.
**/
public void setVirtualThreads(boolean virtualThreads) throws PropertyVetoException
{
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Setting thread used:", virtualThreads);

if (propertiesFrozen_)
{
Trace.log(Trace.ERROR, "Cannot set thread used after connection has been made.");
throw new ExtendedIllegalStateException("threadUsed", ExtendedIllegalStateException.PROPERTY_NOT_CHANGED);
}

if (propertyChangeListeners_ == null && vetoableChangeListeners_ == null)
virtualThreads_ = virtualThreads;
else
{
Boolean oldValue = Boolean.valueOf(virtualThreads_);
Boolean newValue = Boolean.valueOf(virtualThreads);

if (vetoableChangeListeners_ != null)
vetoableChangeListeners_.fireVetoableChange("virtualThreads", oldValue, newValue);

virtualThreads_ = virtualThreads;
if (propertyChangeListeners_ != null)
propertyChangeListeners_.firePropertyChange("virtualThreads", oldValue, newValue);
}
}

/**
* Sets the indicator for whether the default user is used. The default user is used if a system name is provided,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/ibm/as400/access/AS400ConnectionPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class AS400ConnectionPool extends ConnectionPool implements Serializable,
private static final String PRETEST_CONNECTIONS_PROPERTY = "pretestConnections";
private static final String RUN_MAINTENANCE_PROPERTY = "runMaintenance";
private static final String THREAD_USED_PROPERTY = "threadUsed";
private static final String VIRTUAL_THREADS_PROPERTY = "virtualThreads";

/**
Indicates that the CCSID used for new connections is the same as the system default CCSID.
Expand Down Expand Up @@ -172,6 +173,9 @@ public AS400ConnectionPool()
case THREAD_USED_PROPERTY:
setThreadUsed(Boolean.parseBoolean(value));
break;
case VIRTUAL_THREADS_PROPERTY:
setVirtualThreads(Boolean.parseBoolean(value));
break;
default:
if (SocketProperties.isSocketProperty(property)) {
if (socketProperties_ == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/as400/access/AS400Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface AS400Impl
// Set the service ports to their default values.
void setServicePortsToDefault(String systemName);
// Set significant instance variables into implementation object.
void setState(SSLOptions useSSLConnection, boolean canUseNativeOptimization, boolean threadUsed, int ccsid, String nlv, SocketProperties socketProperties, String ddmRDB, boolean mustUseNetSockets, boolean mustUseSuppliedProfile, boolean mustAddLanguageLibrary);
void setState(SSLOptions useSSLConnection, boolean canUseNativeOptimization, boolean threadUsed, boolean virtualThreads, int ccsid, String nlv, SocketProperties socketProperties, String ddmRDB, boolean mustUseNetSockets, boolean mustUseSuppliedProfile, boolean mustAddLanguageLibrary);
SignonInfo setState(AS400Impl impl, CredentialVault credVault);
// Sign-on to system.
SignonInfo signon(String systemName, boolean systemNameLocal, String userId, CredentialVault vault, String gssName) throws AS400SecurityException, IOException;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ibm/as400/access/AS400ImplProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ public void setServicePortsToDefault(String systemName)

// Set the significant instance variables for the AS400ImplRemote object.
@Override
public void setState(SSLOptions useSSLConnection, boolean canUseNativeOptimization, boolean threadUsed, int ccsid, String nlv, SocketProperties socketProperties, String ddmRDB, boolean mustUseNetSockets, boolean mustUseSuppliedProfile, boolean mustAddLanguageLibrary)
public void setState(SSLOptions useSSLConnection, boolean canUseNativeOptimization, boolean threadUsed, boolean virtualThreads, int ccsid, String nlv, SocketProperties socketProperties, String ddmRDB, boolean mustUseNetSockets, boolean mustUseSuppliedProfile, boolean mustAddLanguageLibrary)
{
try
{
connection_.callMethod(pxId_, "setState", new Class[] { SSLOptions.class, Boolean.TYPE, Boolean.TYPE, Integer.TYPE, String.class, SocketProperties.class, String.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE }, new Object[] { useSSLConnection, Boolean.valueOf(canUseNativeOptimization), Boolean.valueOf(threadUsed), Integer.valueOf(ccsid), nlv, socketProperties, ddmRDB, Boolean.valueOf(mustUseNetSockets), Boolean.valueOf(mustUseSuppliedProfile), Boolean.valueOf(mustAddLanguageLibrary) } );
connection_.callMethod(pxId_, "setState", new Class[] { SSLOptions.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Integer.TYPE, String.class, SocketProperties.class, String.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE }, new Object[] { useSSLConnection, Boolean.valueOf(canUseNativeOptimization), Boolean.valueOf(threadUsed), Boolean.valueOf(virtualThreads), Integer.valueOf(ccsid), nlv, socketProperties, ddmRDB, Boolean.valueOf(mustUseNetSockets), Boolean.valueOf(mustUseSuppliedProfile), Boolean.valueOf(mustAddLanguageLibrary) } );
}
catch (InvocationTargetException e)
{
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/ibm/as400/access/AS400ImplRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class AS400ImplRemote implements AS400Impl
private boolean canUseNativeOptimization_ = true;
// Flag that indicates if we use threads in communication with the host servers.
private boolean threadUsed_ = true;
// Flag that indicates if we use virtual threads in communication with the host servers.
private boolean virtualThreads_ = true;

// CCSID to use in conversations with the system.
private int ccsid_ = 0;
Expand Down Expand Up @@ -1684,7 +1686,7 @@ synchronized AS400Server getConnection(int service, int overridePort, boolean fo
// the AS400Server object before passing it back to the caller.

// Construct a new server...
server = (threadUsed_) ? new AS400ThreadedServer(this, service, socketContainer, jobString)
server = (threadUsed_) ? new AS400ThreadedServer(this, service, socketContainer, jobString, virtualThreads_)
: new AS400NoThreadServer(this, service, socketContainer, jobString);
}
else
Expand Down Expand Up @@ -1795,7 +1797,7 @@ private AS400Server getConnectionViaHOSTCNN(int service, int overridePort, bool
jobString = obtainJobIdForConnection(HCSRouteReply.getJobNameBytes());

// Construct a new server...
return (threadUsed_) ? new AS400ThreadedServer(this, service, socketContainer, jobString)
return (threadUsed_) ? new AS400ThreadedServer(this, service, socketContainer, jobString, virtualThreads_)
: new AS400NoThreadServer(this, service, socketContainer, jobString);
}
catch (IOException | AS400SecurityException | RuntimeException e)
Expand Down Expand Up @@ -3251,7 +3253,7 @@ public void setServicePortsToDefault(String systemName) {
// Set the state variables for this implementation object.
@Override
public void setState(SSLOptions useSSLConnection,
boolean canUseNativeOptimization, boolean threadUsed, int ccsid,
boolean canUseNativeOptimization, boolean threadUsed, boolean virtualThreads, int ccsid,
String nlv, SocketProperties socketProperties, String ddmRDB,
boolean mustUseNetSockets, boolean mustUseSuppliedProfile,
boolean mustAddLanguageLibrary)
Expand All @@ -3274,6 +3276,7 @@ public void setState(SSLOptions useSSLConnection,
useSSLConnection_ = useSSLConnection;
canUseNativeOptimization_ = canUseNativeOptimization;
threadUsed_ = threadUsed;
virtualThreads_ = virtualThreads;
if (ccsid != 0)
{
userOverrideCcsid_ = true;
Expand Down
45 changes: 44 additions & 1 deletion src/main/java/com/ibm/as400/access/AS400JDBCDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ public Connection getConnection(String user, char[] password, char[] additionalA
{ /*ignore*/ //@PDA
} //@PDA

try
{
if(as400_.isVirtualThreads())
as400Object.setVirtualThreads(true);
} catch (PropertyVetoException pve)
{ /*ignore*/
}

//set gui available on the new object to false if user turned prompting off
try
{ //@C2A
Expand Down Expand Up @@ -1211,6 +1219,15 @@ public boolean isUseSock5()
return properties_.getBoolean(JDProperties.USE_SOCK5);
}

/**
* Indicates whether virtual threads are used.
* @return Returns true if the driver will try to use virtual threads
**/
public boolean isVirtualThreads()
{
return properties_.getBoolean(JDProperties.VIRTUAL_THREADS);
}

/**
* Returns the Reference object for the data source object.
* This is used by JNDI when bound in a JNDI naming service.
Expand Down Expand Up @@ -3911,7 +3928,6 @@ public void setUseSock5(boolean value)
if (JDTrace.isTraceOn())
JDTrace.logInformation (this, property + ": " + value);
}


/**
* Sets the source of the text for REMARKS columns in ResultSets returned
Expand Down Expand Up @@ -4374,6 +4390,33 @@ public void setThreadUsed(boolean threadUsed)
JDTrace.logInformation (this, "threadUsed: " + threadUsed); //@A8C
}

/**
* Sets the flag to use virtual threads
* @param virtualThreads true if a virtual thread is used; false otherwise.
* The default value is false.
**/
public void setVirtualThreads(boolean virtualThreads)
{
String property = JDProperties.VIRTUAL_THREADS_ ;
Boolean oldValue = Boolean.valueOf(isVirtualThreads());
Boolean newValue = Boolean.valueOf(virtualThreads);

properties_.setString(JDProperties.VIRTUAL_THREADS, virtualThreads ? TRUE_ : FALSE_);

try
{
as400_.setVirtualThreads(virtualThreads);
}
catch (PropertyVetoException pve)
{ /* Will never happen */
}

changes_.firePropertyChange(property, oldValue, newValue);

if (JDTrace.isTraceOn())
JDTrace.logInformation (this, property + ": " + virtualThreads);
}

/**
* Sets the time format used in time literals with SQL statements.
* @param timeFormat The time format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,13 @@ public class AS400JDBCDataSourceBeanInfo extends SimpleBeanInfo {
useSock5.setDisplayName(AS400JDBCDriver.getResource("PROP_NAME_USE_SOCK5", null));
useSock5.setShortDescription(AS400JDBCDriver.getResource("USE_SOCK5_DESC", null));


PropertyDescriptor virtualThreads = new PropertyDescriptor("virtualThreads", beanClass, "isVirtualThreads",
"setVirtualThreads");
virtualThreads.setBound(true);
virtualThreads.setConstrained(false);
virtualThreads.setDisplayName(AS400JDBCDriver.getResource("PROP_NAME_VIRTUAL_THREADS", null));
virtualThreads.setShortDescription(AS400JDBCDriver.getResource("VIRTUAL_THREADS_DESC", null));

PropertyDescriptor keepAlive = new PropertyDescriptor("keepAlive", beanClass, "isKeepAlive",
"setKeepAlive");
keepAlive.setBound(true);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/ibm/as400/access/AS400JDBCDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ static AS400 initializeAS400(JDDataSourceURL dataSourceUrl,
String prompt = jdProperties.getString (JDProperties.PROMPT); // @B8C
boolean secure = jdProperties.getBoolean (JDProperties.SECURE);
boolean useThreads = jdProperties.getBoolean(JDProperties.THREAD_USED);
boolean virtualThreads = jdProperties.getBoolean(JDProperties.VIRTUAL_THREADS);

// Updated 2023 to not pass old Properties information.
// Everything should be in the JDProperties object
Expand Down Expand Up @@ -1236,6 +1237,13 @@ else if (clearPassword == null)
}
catch(java.beans.PropertyVetoException e){
}
//Determine if virtual threads should be used in communication with the host servers
try{
if(virtualThreads)
as400.setVirtualThreads(virtualThreads);
}
catch(java.beans.PropertyVetoException e){
}
if(forcePrompt) //@prompt
as400.forcePrompt(); //@prompt
return as400;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/ibm/as400/access/AS400JDBCManagedDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,15 @@ public boolean isSecureCurrentUser() {
public boolean isUseSock5() {
return properties_.getBoolean(JDProperties.USE_SOCK5);
}
/**
* Indicates whether virtual threads are used
*
* @return true if virtual threads are used; false otherwise. The default value
* is false.
**/
public boolean isVirtualThreads() {
return properties_.getBoolean(JDProperties.VIRTUAL_THREADS);
}

/**
* Indicates whether a thread is used.
Expand Down Expand Up @@ -4546,6 +4555,15 @@ public void setUseSock5(boolean useSock5) {
properties_.setString(JDProperties.USE_SOCK5, FALSE_);
}

/**
* Sets whether virtual threads should be used
*
* @param virtualThreads true if virtual threads should be used. The
* default value is false.
**/
public void setVirtualThreads(boolean virtualThreads) {
properties_.setString(JDProperties.VIRTUAL_THREADS, virtualThreads ? TRUE_ : FALSE_);
}

/**
* Sets whether lock sharing is allowed for loosely coupled transaction
Expand Down
Loading