我用一个固定大小的线程池Executors.newFixedThreadPool(2),我执行了10个Runnable对象.我设置断点并追踪执行.但是,fixedSizeThreadPool.awaitTermination()即使完成了所有任务,也不允许我继续.
基本上:
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(2);
for (int i = 0; i < 10; ++i) {
fixedSizeThreadPool.execute(myRunables[i]);
}
try {
fixedSizeThreadPool.awaitTermination(timeout, timeoutUnits);
} catch (Exception e) { }
System.out.println("done!");
Run Code Online (Sandbox Code Playgroud)
但这总是被困住awaitTermination.怎么了?
所以我使用的是Quartz jar:quartz-all-2.0.1.jar.从自述文件中可以看出,这个罐子应该可以设置所有东西.但是,当我尝试使用创建SchedulerFactory时
SchedulerFactory sf = new StdSchedulerFactory();
Run Code Online (Sandbox Code Playgroud)
我明白了:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:268)
at WebScraper.Main.main(Main.java:19)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Run Code Online (Sandbox Code Playgroud)
我也很困惑,因为在我尝试运行程序之前Eclipse没有显示任何错误.谢谢你的帮助.
这个准备好的语句对我来说似乎是有效的SQL.
PreparedStatement dropTable = cnx.prepareStatement(
"DROP TABLE IF EXISTS ?");
dropTable.setString(1, "features");
dropTable.execute();
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我得到错误:
线程"main"中的异常com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法中有错误; 检查与MySQL服务器版本相对应的手册,以便在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:)的sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)第1行的''features''附近使用正确的语法. 57)在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:532)at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)在com.mysql.jdbc.Util.getInstance(Util.java:381)的com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)com.mysql.jdbc.SQLError.createSQLException(SQLError.java: 956)com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java) :1959)com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:26)48)at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1356)at doriangray.db.TestSetup.main(TestSetup.java:62 )
有人在这看到问题吗?我很难过.
我将我的应用程序从spring boot 1.5.9.RELEASE升级到2.0.0.RELEASE,我无法再导入org.springframework.boot.context.embedded.LocalServerPort.我正在使用它来注入服务器在测试期间运行的端口:
public class Task1Test {
@LocalServerPort
private int port;
Run Code Online (Sandbox Code Playgroud)
在春天发行说明没有提到这一点拆卸和@LocalServerPort并没有过时.
我可以使用Spring Boot 2.0中的等效项吗?
编辑:我很确定课程已经消失了.我收到这些编译错误:
[ERROR] ... Task1Test.java:[12,49]package org.springframework.boot.context.embedded does not exist
[ERROR] ... Task1Test.java:[46,6] cannot find symbol
symbol: class LocalServerPort
Run Code Online (Sandbox Code Playgroud) 我有一个带有此安全配置的 Spring boot 应用程序:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers().frameOptions().sameOrigin().and()
.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class)
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/authenticate/**", "/h2-console/**").permitAll()
.anyRequest().authenticated();
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序代码中,我抛出一个 ResponseStatusException:
if (existingTenant.isPresent()) {
throw new ResponseStatusException(
HttpStatusCode.valueOf(400),
"Tenant with name " + tenant.name() + " already exists");
}
Run Code Online (Sandbox Code Playgroud)
但我得到的 api 响应是 403:
* Mark bundle as not supporting multiuse
< HTTP/1.1 403
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Yesod并持久创建一个网站.我对如何使用持久API感到有点困惑.
这是我的两张桌子
Feed
url Text
UniqueFeed url
Subscription
feed FeedId
title Text
UniqueSubscription feed
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建Feed,如果具有该URL的Feed不存在,然后添加订阅该订阅源,如果订阅尚不存在.
postFeedR :: Handler RepHtml
postFeedR = do
url <- runInputPost $ ireq urlField "url"
title <- runInputPost $ ireq textField "title"
runDB $ do
feedId <- insertFeed $ UniqueFeed url
subscriptionId <- insertSubscription feedId title
return
defaultLayout [whamlet| <p>done|]
insertFeed url = do
f <- insertBy $ UniqueFeed url
case f of
Left (Entity uid _) -> uid
Right (Key uid) -> do
(Key uid) …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个扩展到周围JPanel的javafx WebView.根据这一线索:http://www.coderanch.com/t/634791/JavaFX/java/Resizing-HTMLEditor-JavaFX,有在需要调用web视图中的错误GridPane.setHgrow,并GridPane.setVgrow在网页视图.我用这些调用填充了我的代码,但WebView仍然是600x800px.
请注意,场景具有蓝色背景,因此您可以看到javafx内容确实填充了整个JPanel.但是WebView没有填充javafx组/场景.
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
public class Main {
private void initAndShowGUI() {
// This method is invoked on the EDT thread
JFrame frame = new JFrame("Swing and JavaFX");
frame.setSize(1000, 1000);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new BorderLayout(0, 0));
frame.getContentPane().add(panel, BorderLayout.CENTER);
JButton button = new JButton("button");
panel.add(button, …Run Code Online (Sandbox Code Playgroud) 我正在尝试捕获在wx.Frame中发生的键盘事件,我希望以下代码能够捕获这些事件.但是,当我运行代码时,从不调用处理程序OnKeyDown:
import logging as log
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_KEY_UP, self.OnKeyDown)
self.Bind(wx.EVT_CHAR, self.OnKeyDown)
self.SetFocus()
self.Show(True)
def OnKeyDown(self, event=None):
log.debug("OnKeyDown event %s" % (event))
if __name__ == "__main__":
app = wx.App(False)
gui = MainWindow(None, "test")
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)
如果有人知道如何做到这一点,我将不胜感激.
我无法解释 MySql(5.7,InnoDB)的死锁输出。我知道死锁最终会通过更改应用程序级别代码来解决,并且您无法从这段代码中找到根本原因。然而,希望有人能够告诉我为什么我对这个 MySql 诊断的解释是不正确的。
------------------------
LATEST DETECTED DEADLOCK
------------------------
2018-04-09 19:41:39 0x2b7323ef1700
*** (1) TRANSACTION:
TRANSACTION 33312589, ACTIVE 16 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 1136, 1 row lock(s)
MySQL thread id 150744, OS thread handle 47781157312256, query id 53141856 ec2-34-250-106-67.eu-west-1.compute.amazonaws.com 34.250.106.67 sc_appuser3 statistics
/* requestId: 11e8-3c2d-fb145a10-b404-0242ac110003 */ SELECT locator FROM policy WHERE locator = 'df0d7ef5-2e14-4664-90b2-2bfb3f35cce2' AND tenant_locator = '8df5d824-6de9-4e21-8135-b19303aec800' FOR UPDATE
*** (1) WAITING FOR THIS LOCK …Run Code Online (Sandbox Code Playgroud) 快问,这有什么问题?
(get) :: [a] -> Int -> a -- <- line 21
(x:xs) get 0 = x
(x:xs) get (n+1) = xs get n
Run Code Online (Sandbox Code Playgroud)
当我尝试加载包含该代码的文件时,ghci会出现此错误.
Prelude> :load ch6.hs
[1 of 1] Compiling Main ( ch6.hs, interpreted )
ch6.hs:21:0: Invalid type signature
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
我正试图让一个中缀运算符.