我正在尝试模拟一个场景,其中我的服务失去与数据库的连接,并且无法INSERT通过阻止与 iptables 的连接来执行此操作,但我无法使该executeQuery()方法超时。
我所做的是为PreparedStatement设置一个超时,如下所示statement.setQueryTimeout(5)。这是代码。
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://db-url/db");
config.setUsername("user");
config.setPassword("passwd");
config.setMaximumPoolSize(10);
config.setAutoCommit(false);
config.setConnectionTimeout(5000);
config.setDriverClassName("com.mysql.jdbc.Driver");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("autoReconnect", "true");
final HikariDataSource pool = new HikariDataSource(config);
final String query = "INSERT INTO xtable VALUES (?, ?, ?, ?, ?)";
try ( Connection connection = pool.getConnection() )
{
try ( PreparedStatement statement = connection.prepareStatement(query) )
{
// this is what I expect to work
statement.setQueryTimeout(5);
for ( Info info : infos …Run Code Online (Sandbox Code Playgroud) 所以,首先我创建一个像这样的新片段
ft = fm.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.replace(R.id.main_content_frame, cFr, "CARS");
ft.addToBackStack(null);
ft.commit();
Run Code Online (Sandbox Code Playgroud)
后来我把它删除了
fm.popBackStack();
ft = fm.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_NONE);
ft.remove(fm.findFragmentByTag("CARS")).commit();
Run Code Online (Sandbox Code Playgroud)
但是关闭过渡是通过TRANSIT_FRAGMENT_OPEN动画完成的(或者我认为是默认情况下相反),我清楚地设定了TRANSIT_NONE.
有什么想法吗?