我已经成功地启动并运行了我的第一个Vaadin 7应用程序,这是由Maven原型为我创建的.此应用程序的模板显示了窗口小部件的布局,窗口小部件和业务逻辑(单击按钮),所有这些都在MyUI类中定义.
我从哪里开始?我只是继续添加内容MyUI还是有更好的方法来构建我的应用程序?
这是MyUIMaven原型给我的Java源代码.
package com.example.vaadinlayoutsexample;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
/**
* This UI is the application entry point. A UI may either represent a browser window
* (or tab) or some part of a html page where a Vaadin application is embedded.
* <p>
* The UI is initialized using {@link #init(VaadinRequest)}. …Run Code Online (Sandbox Code Playgroud) 我正在将字符串类型的日期解析为日期格式,但每次都有此异常
java.text.ParseException: Unparseable date: "2016-05-21T00:00:00" (at offset 4)
Run Code Online (Sandbox Code Playgroud)
我的代码是:
String d = "2016-05-21T00:00:00";
DateFormat df = new SimpleDateFormat("yyyy MM dd HH:mm:ss", Locale.ENGLISH);
Date myDate = null;
try {
myDate = df.parse(d);
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 在Android中,我用来java.util.Calendar获取格式为昨天的日期yyyy-MM-dd'T'hh:mm:ss'Z'。例如,如果今天是31 May 2017,我想将昨天的日期设为2017-05-30T00:00:00Z。
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
// Date End = yesterday
calendar.add(Calendar.DATE, -1);
Date dateEnd = calendar.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
this.dateEndStr = formatter.format(dateEnd);
Run Code Online (Sandbox Code Playgroud)
我期望输出为2017-05-30T00:00:00Z. 但它给了我2017-05-30T12:00:00Z。
这里有什么问题吗?与时区有关吗?我的时区是GMT/UTC + 08:00 hour.
有什么方法可以确定两个BigDecimal对象中的哪一个是比(if或三元运算符)调用更简单的数字(更小)BigDecimal::compareTo?
鉴于:
BigDecimal x = … ;
BigDecimal y = … ;
Run Code Online (Sandbox Code Playgroud)
要么:
if( x.compareTo( y ) < 0 ) {
return x ;
} else {
return y ;
}
Run Code Online (Sandbox Code Playgroud)
要么:
BigDecimal lower = ( x.compareTo( y ) < 0 ) ? x : y ; // If x is smaller than y, use x. If x is greater than or equal to y, use y.
Run Code Online (Sandbox Code Playgroud) 我正在尝试了解Hazelcast库。在线研究表明它是一个内存数据网格并且适用于分布式网络。除此之外,我对理解这一点感到非常困惑。
如果错了请纠正我(我的理解)。这里在分布式网络上工作意味着一些数据存储在 Hazelcast 的内存数据网格中,集群中的所有节点都可以访问它?这是正确的吗 ?集群中的任何节点都可以对内存中的数据网格执行(插入、删除或更新),并且所有节点都可以使用该网格。
谁能帮我用任何例子简单地解释 Hazelcast 的主要目的是什么?
我从日期生成数字,我使用的是Integer.parseInt(myDateNumberString).
我的问题是,如果数字太大,它会给我一个错误.
public Integer currentDate(){
String current_date = new SimpleDateFormat("yyyyMMddHHmm").format(Calendar.getInstance().getTime());
//int _current_date = Integer.parseInt(current_date); // Error, too big number
int _current_date = new BigInteger(current_date).intValue();
return _current_date; // Error, output: -51212897
}
Run Code Online (Sandbox Code Playgroud)
我希望获得价值,201812250203
如果我的日期格式没有mm它是好的,但我需要声明它.
我的主要方法必须有一个由2个团队名称组成的数组,我想知道是否有一种方法可以在业务类中使用该数组,然后将其带到测试人员类中以设置名称。
//instance variables
String[] names = new String[2];
int[] score;
//no-arg constructor
public ReHW3Biz() {
names[0] = "Null";
names[1] = "Null";
score[] = 0;
}
//getters and setters
public String[] getName(String[] names)
{
this.names = names;
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误消息是:
此方法必须返回String []类型的结果
我试图得到一个月的第一个星期日。我达到的是获得一年中的所有星期日
import static java.time.temporal.TemporalAdjusters.firstInMonth;
public static void FindAllSundaysOfTheYear () {
// Create a LocalDate object that represent the first day of the year.
int year = 2021;
LocalDate now = LocalDate.of(year, Month.JANUARY, 1);
// Find the first Sunday of the year
LocalDate sunday = now.with(firstInMonth(DayOfWeek.SUNDAY));
do {
// Loop to get every Sunday by adding Period.ofDays(7) the the current Sunday.
System.out.println(sunday.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)));
sunday = sunday.plus(Period.ofDays(7));
} while (sunday.getYear() == year);
}
Run Code Online (Sandbox Code Playgroud)
输出是
Sunday, January 5, 2020
Sunday, January 12, 2020
Sunday, …Run Code Online (Sandbox Code Playgroud)我创建一个记录用户:
\npublic record User(String name, int age, List<String> skills, boolean isActive) {\n}\nRun Code Online (Sandbox Code Playgroud)\n和用户列表:
\n private static List<User> prepareData() {\n List<User> users = new ArrayList<>();\n\n users.add(new User("Kamil", 35, List.of("Java", "Python", "JavaScript"), true));\n users.add(new User("Mariusz", 36, List.of("Java", "C++", "C#"), true));\n users.add(new User("Dominik", 30, List.of("Java", "Dart", "Python"), false));\n users.add(new User("Paulina", 36, List.of("PHP", "SQL", "Python"), false));\n users.add(new User("Rafa\xc5\x82", 40, List.of("C#", "Dart"), true));\n users.add(new User("Agnieszka", 29, List.of("Java", "Scala", "Kotlin", "Haskell", "Clojure"), false));\n users.add(new User("Weronika", 43, List.of("Python", "C#", "VBA"), true));\n\n return users;\n }\nRun Code Online (Sandbox Code Playgroud)\n … 我想创建在单独的 Java 线程池上运行的虚拟线程池。
这是我试图创建的架构:
这是为了让我能够创建单独的池来在一个 JVM 中运行批处理任务,并利用每个池的 n:m 映射的虚拟线程。因此,如果我有 12 个核心,那么我可以创建 2 个 6 线程的线程池。每个池只会执行一个特定的任务。每个池将有 N 个虚拟线程。因此,这里的映射将是 2 个 {N VirtualThreads -> 6 Platform Threads} 池。
TLDR,我想限制虚拟线程池可以运行的 PlatformThreads 数量。
我能想到的一件事是,创建线程池,当传入可运行对象时,在 run 方法内我可以创建虚拟线程,但不确定它有多实用,以及我是否会得到我想要的池分区。这种方法的另一个问题是,虚拟线程将仅在一个 java 线程中运行,因此没有 N:M 映射
java threadpoolexecutor java-threads virtual-threads java-21