diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java index 3f2365734a..799f87464b 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.lang.Nullable; * @see ScheduledTaskRegistrar#scheduleCronTask(CronTask) * @see ScheduledTaskRegistrar#scheduleFixedRateTask(FixedRateTask) * @see ScheduledTaskRegistrar#scheduleFixedDelayTask(FixedDelayTask) + * @see ScheduledFuture */ public final class ScheduledTask { @@ -54,11 +55,24 @@ public final class ScheduledTask { /** * Trigger cancellation of this scheduled task. + *
This variant will force interruption of the task if still running. + * @see #cancel(boolean) */ public void cancel() { + cancel(true); + } + + /** + * Trigger cancellation of this scheduled task. + * @param mayInterruptIfRunning whether to force interruption of the task + * if still running (specify {@code false} to allow the task to complete) + * @since 5.3.18 + * @see ScheduledFuture#cancel(boolean) + */ + public void cancel(boolean mayInterruptIfRunning) { ScheduledFuture> future = this.future; if (future != null) { - future.cancel(true); + future.cancel(mayInterruptIfRunning); } } diff --git a/spring-core/src/main/java/org/springframework/asm/ClassReader.java b/spring-core/src/main/java/org/springframework/asm/ClassReader.java index 1b14e0e02a..725ba340bb 100644 --- a/spring-core/src/main/java/org/springframework/asm/ClassReader.java +++ b/spring-core/src/main/java/org/springframework/asm/ClassReader.java @@ -313,7 +313,7 @@ public class ClassReader { if (inputStream == null) { throw new IOException("Class not found"); } - int bufferSize = calculateBufferSize(inputStream); + int bufferSize = computeBufferSize(inputStream); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { byte[] data = new byte[bufferSize]; int bytesRead; @@ -336,13 +336,12 @@ public class ClassReader { } } - private static int calculateBufferSize(final InputStream inputStream) throws IOException { + private static int computeBufferSize(final InputStream inputStream) throws IOException { int expectedLength = inputStream.available(); /* - * Some implementations can return 0 while holding available data - * (e.g. new FileInputStream("/proc/a_file")) - * Also in some pathological cases a very small number might be returned, - * and in this case we use default size + * Some implementations can return 0 while holding available data (e.g. new + * FileInputStream("/proc/a_file")). Also in some pathological cases a very small number might + * be returned, and in this case we use a default size. */ if (expectedLength < 256) { return INPUT_STREAM_DATA_CHUNK_SIZE; @@ -861,7 +860,7 @@ public class ClassReader { currentOffset += 2; } - // Read the 'provides_count' and 'provides' fields. + // Read the 'provides_count' and 'provides' fields. int providesCount = readUnsignedShort(currentOffset); currentOffset += 2; while (providesCount-- > 0) { diff --git a/spring-core/src/main/java/org/springframework/asm/ClassWriter.java b/spring-core/src/main/java/org/springframework/asm/ClassWriter.java index de285663ee..045d571312 100644 --- a/spring-core/src/main/java/org/springframework/asm/ClassWriter.java +++ b/spring-core/src/main/java/org/springframework/asm/ClassWriter.java @@ -65,6 +65,12 @@ public class ClassWriter extends ClassVisitor { */ public static final int COMPUTE_FRAMES = 2; + /** + * The flags passed to the constructor. Must be zero or more of {@link #COMPUTE_MAXS} and {@link + * #COMPUTE_FRAMES}. + */ + private final int flags; + // Note: fields are ordered as in the ClassFile structure, and those related to attributes are // ordered as in Section 4.7 of the JVMS. @@ -248,23 +254,39 @@ public class ClassWriter extends ClassVisitor { * @param classReader the {@link ClassReader} used to read the original class. It will be used to * copy the entire constant pool and bootstrap methods from the original class and also to * copy other fragments of original bytecode where applicable. - * @param flags option flags that can be used to modify the default behavior of this class.Must be - * zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. These option flags do - * not affect methods that are copied as is in the new class. This means that neither the + * @param flags option flags that can be used to modify the default behavior of this class. Must + * be zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. These option flags + * do not affect methods that are copied as is in the new class. This means that neither the * maximum stack size nor the stack frames will be computed for these methods. */ public ClassWriter(final ClassReader classReader, final int flags) { super(/* latest api = */ Opcodes.ASM9); + this.flags = flags; symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader); if ((flags & COMPUTE_FRAMES) != 0) { - this.compute = MethodWriter.COMPUTE_ALL_FRAMES; + compute = MethodWriter.COMPUTE_ALL_FRAMES; } else if ((flags & COMPUTE_MAXS) != 0) { - this.compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL; + compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL; } else { - this.compute = MethodWriter.COMPUTE_NOTHING; + compute = MethodWriter.COMPUTE_NOTHING; } } + // ----------------------------------------------------------------------------------------------- + // Accessors + // ----------------------------------------------------------------------------------------------- + + /** + * Returns true if all the given flags were passed to the constructor. + * + * @param flags some option flags. Must be zero or more of {@link #COMPUTE_MAXS} and {@link + * #COMPUTE_FRAMES}. + * @return true if all the given flags, or more, were passed to the constructor. + */ + public boolean hasFlags(final int flags) { + return (this.flags & flags) == flags; + } + // ----------------------------------------------------------------------------------------------- // Implementation of the ClassVisitor abstract class // ----------------------------------------------------------------------------------------------- diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java index 988c1c22d7..716a6c1cf0 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java @@ -79,7 +79,7 @@ import org.springframework.transaction.support.ResourceTransactionDefinition; * @author Costin Leau * @since 2.0 * @see HibernateJpaVendorAdapter - * @see org.hibernate.Session#setFlushMode + * @see org.hibernate.Session#setHibernateFlushMode * @see org.hibernate.Transaction#setTimeout */ @SuppressWarnings("serial") @@ -349,10 +349,9 @@ public class HibernateJpaDialect extends DefaultJpaDialect { this.readOnly = readOnly; } - @SuppressWarnings("deprecation") public void resetSessionState() { if (this.previousFlushMode != null) { - this.session.setFlushMode(this.previousFlushMode); + this.session.setHibernateFlushMode(this.previousFlushMode); } if (this.needsConnectionReset && this.session.getJdbcCoordinator().getLogicalConnection().isPhysicallyConnected()) {