上周末我打电话给客户,告诉我他们的Java程序在导入数据时没有响应.数据是一个简单的Excel工作簿,包含4个工作表.正在从列中读取所有数据并将其添加到数据库中.
所以我开始调查并得到了一些奇怪的结果.
第一次运行
第二次运行
第一次运行
在这种情况下,我遇到了客户报告的相同问题,程序在经过一段时间的导入过程后停止响应.这是因为我达到了最大堆大小(据我所知)(红色圆圈).
第二次运行
所以我决定通过在JNLP文件中添加以下内容来增加初始堆大小和最大堆大小:initial-heap-size="512m" max-heap-size="1024m".当我再次测试导入时,它似乎工作,但是我注意到与前两种情况相比,使用的内存要多得多:
initial-heap-size="512m" max-heap-size="1024m"为此问题添加了有效的解决方案?我偶然发现了(在我眼里)一个愚蠢的问题.但是我没有找到解决方案(可能是因为没有使用正确的搜索关键字,或者当它变得容易时使其变得太难......)场景:
我有500个客户的组合框.我必须选择一个客户.
在Swing中,当列表关闭并且您开始键入时,它会自动跳转到键入的字母.例如:
项目:
当组合框列表打开时,我只需键入"R",然后在跳转时跳转到以"R"开头的第一个客户.在javafx 2中它似乎没有那种行为...是否有一些选项我必须启用或者我应该做一些事情,比如使用可编辑的组合框来制作一个filter()在每个按键上触发的方法?
编辑:根据Bhupendra的答案解决:
public class FilterComboBox<T> extends ComboBox<T> {
private final FilterComboBox<T> fcbo = this;
//private FilterComboBox fcbo = this;
private ObservableList<T> items;
private ObservableList<T> filter;
private String s;
private Object selection;
private class KeyHandler implements EventHandler< KeyEvent> {
private SingleSelectionModel<T> sm;
public KeyHandler() {
sm = getSelectionModel();
s = "";
}
@Override
public void handle(KeyEvent event) {
filter.clear();
// handle non alphanumeric keys …Run Code Online (Sandbox Code Playgroud) 我有一个存在于User对象之外的TreeView。TreeView代表用户的层次结构:
初始化TreeView时,每个TreeItem都会折叠。但是,可能是在加载FXML时,从另一个FXML文件传递了TreeItem对象。例如:User3已通过:
selectedUserTreeItem = (TreeItem<User>) currentNavigation.getPassthroughObject(); //this is the User3 TreeItem
Run Code Online (Sandbox Code Playgroud)
我尝试使用递归函数来扩展所有父节点 selecterUserTreeItem
if (selectedUserTreeItem != null) {
expandTreeView(selectedUserTreeItem);
}
tvUsers.setRoot(rootItem);
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的内容:
private void expandTreeView(TreeItem<User> selectedItem) {
if (selectedItem != null) {
System.out.println(selectedItem);
if (selectedItem.isLeaf() == false) {
selectedItem.setExpanded(true);
}
TreeItem<User> parent = selectedItem.getParent();
expandTreeView(parent);
} else {
System.out.println("null");
}
}
Run Code Online (Sandbox Code Playgroud)
我认为它必须与以下事实有关:该函数是一个void函数,它应该返回一个我猜想的TreeItem对象,但是由于某种原因,我没有成功执行该操作。
有人可以指出我正确的方向吗?
我尝试将自定义标志从npm脚本传递到我的webpack配置,但它会导致以下错误.日志
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
ERROR in Entry module not found: Error: Can't resolve '--no-dist' in 'C:\Users\user\gitroot\MyProject\sharepoint'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-project@4.0.0 dev: `webpack --mode development -- --no-dist`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the my-project@4.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)
的package.json
...
"scripts": …Run Code Online (Sandbox Code Playgroud) 首先,我对这篇长文章表示歉意。这是关于此问题的上一个问题(7u21更新后弹出“需要身份验证”窗口)的继续,但我缩小了搜索范围。简而言之,似乎我的BASIC身份验证自Java 7u21起就被破坏了。
通过JNLP文件启动的Applet根本无法稳定运行,并提供了身份验证弹出窗口。
设置
首先,我已经建立了一个带有usertable和grouptable 的MySQL数据库。


接下来,我在Glassfish中设置了一个jdbcRealm。注意,数据库用户和数据库密码字段为空,因为我使用的是JNDI(请参见下文):
Glassfish领域设置:

JDNI配置(如domain.xml文件中所示):
<jdbc-connection-pool connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" wrap-jdbc-objects="false" res-type="javax.sql.DataSource" name="mysql_mit_rohhPool">
<property name="URL" value="jdbc:mysql://localhost:3306/mit?zeroDateTimeBehavior=convertToNull"></property>
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="Password" value="****"></property>
<property name="portNumber" value="3306"></property>
<property name="databaseName" value="mit"></property>
<property name="User" value="****"></property>
<property name="serverName" value="localhost"></property>
</jdbc-connection-pool>
<jdbc-resource pool-name="mysql_mit_rohhPool" jndi-name="jdbc/DB_MIT"></jdbc-resource>
Run Code Online (Sandbox Code Playgroud)
完成此操作后,我将默认领域更改为新创建的jdbcRealm并检查了默认主体到角色的映射:

测试中
毕竟,为了进行测试,我在Netbeans中创建了一个简单的Web服务,该服务从数据库中获取了一些国家/地区,并配置了用于BASIC身份验证的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<description>Multiple packages, separated by semicolon(;), can be specified in …Run Code Online (Sandbox Code Playgroud) I'm trying out some custom error handling on my webservice. In my webservice, I created a custom Exception class extending WebApplicationException as described in JAX-RS / Jersey how to customize error handling? :
public class InternalServerErrorException extends WebApplicationException {
public InternalServerErrorException(String message) {
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.header("errorMessage", message).type(MediaType.TEXT_PLAIN).build());
System.out.println(message);
}
}
Run Code Online (Sandbox Code Playgroud)
For testing, I have a simple Country service that gives a list of countries. I made sure that an error will occur to test the throwing of the InternalServerErrorException:
@GET
@Override …Run Code Online (Sandbox Code Playgroud) 我正在研究将我们的项目转换为 Spring Boot 应用程序的概念验证。我有一个具有两种方法的存储库类:保存和查找。
@Repository
public class UserDataRepo {
private EntityManager em;
public boolean save(UserDataModel model) {
try {
UserDataModel existingModel = find(model.getTable(), model.getFieldName();
model.setId(existingModel.getId());
this.em.merge(model);
this.em.flush();
return false;
} catch (NoResultException e) {
this.em.persist(model);
this.em.flush();
return true;
}
}
public UserDataModel find(String table, String field) {
Query query = this.em.createQuery(FIND_USERDATA_STATEMENT);
query.setParameter("table", table);
query.setParameter("fieldName", field);
return (UserDataModel) query.getSingleResult(); // throws NoResultException
}
}
Run Code Online (Sandbox Code Playgroud)
在我的 Spring Boot 应用程序类中,我添加了@EnableJpaRepositories, @EnableTransactionManagement。我的应用程序启动正常,没有任何错误。但正如你所看到的,save方法依赖于find方法来确定是合并还是持久。如果没有记录,find 方法将抛出 NoResultException。我观察到它永远不会落入 save 方法的 catch 块内。Spring Boot 只是抛出一个错误,指出 NoResultException。 …
我刚开始使用 Maven 并想更改我当前的 JavaFX8 FXML 应用程序以使用 Maven。作为测试,我试图从运行在 Glassfish 3 上的网络服务中检索国家/地区列表。
当我运行程序时,这发生在我的 FXML 控制器中initialize():
CountryClientSSL cc = new CountryClientSSL();
cc.setUsernamePassword("username", "password");
ObservableList<Country> olCountries = FXCollections.observableArrayList(cc.findAll());
olCountries.stream().forEach((country) -> {
System.out.println(country.getName());
});
cc.close();
Run Code Online (Sandbox Code Playgroud)
该findAll()方法:
public List<Country> findAll() throws ClientErrorException {
WebTarget resource = webTarget;
resource = resource.path("countries");
System.out.println(resource.getUri().toString());
return resource.request(javax.ws.rs.core.MediaType.APPLICATION_XML).get(new GenericType<List<Country>>(){});
}
Run Code Online (Sandbox Code Playgroud)
如果我在浏览器中对其进行测试,该 URI 看起来不错并且可以使用凭据,但是会引发以下错误:
...
Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V
at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:335)
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:221)
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:59)
at DA.CountryClientSSL.findAll(CountryClientSSL.java:85)
...
Run Code Online (Sandbox Code Playgroud)
我的 pom.xml 文件具有 Jersey 依赖项:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) java ×5
jersey ×3
javafx-2 ×2
rest ×2
web-services ×2
combobox ×1
glassfish ×1
heap-memory ×1
hibernate ×1
javafx ×1
javafx-8 ×1
javascript ×1
jpa ×1
maven ×1
memory ×1
memory-leaks ×1
node.js ×1
npm ×1
recursion ×1
spring ×1
spring-boot ×1
treeview ×1
webpack ×1