我一直在努力为我正在开发的应用程序实现多线程方法。
我想要在并行线程中运行的部分最初是用一个关于列表的 for 循环构建的。
@Service
public ApplicationServiceImpl implements ApplicationService {
@Override
public ResponseEntity<Void> startProcess(List<MyObject> myObjectList) throws Exception {
for (MyObject myObject : myObjectList) {
AnotherTypeOfObject anotherTypeOfObject = runMethodA(myObject);
YetAnotherTypeOfObject yetAnotherTypeOfObject = runMethodB(anotherTypeOfObject);
runMethodC(yetAnotherTypeOfObject, aStringValue, anotherStringValue);
runMethodD(yetAnotherTypeOfObject);
}
}
}
Run Code Online (Sandbox Code Playgroud)
方法private AnotherTypeOfObject runMethodA(MyObject myObject) {...}、private YetAnotherTypeOfObject yetAnotherTypeOfObject(AnotherTypeOfObject anotherTypeOfObject) {...}、private void runMethodC(YetAnotherTypeOfObject yetAnotherTypeOfObject, String aStringValue, String anotherStringValue) {...}和private void runMethodD(MyObject myObject) {...}仅使用局部变量。
我花了很多时间寻找一种解决方案,该解决方案允许触发 100 个线程列表,MyObject而不是一个接一个。
我所做的是创建一个:
@Configuration
@EnableAsync
public class AsyncConfiguration() { …Run Code Online (Sandbox Code Playgroud) 有没有办法只接受材质文本字段中的数字,就像 EditText 一样,其中 inputType 可以指定为数字?
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:hint="Seconds"
app:helperText="Enter numbers only"
app:endIconMode="clear_text"
app:startIconDrawable="@drawable/ic_timer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etTime"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud) 我有一张桌子,里面的一些文字大得惊人。我想确保查询输出中的每一行不超过 100.000 个字符。我怎么做?
这是一个快速示例:
WITH large_texts AS (
(SELECT 'humongous text goes here' AS text ,'1' AS id)
UNION ALL
(SELECT 'small one' AS text ,'2' AS id)
UNION ALL
(SELECT 'and another big one over here' AS text ,'3' AS id)
)
SELECT * FROM large_texts
Run Code Online (Sandbox Code Playgroud)
假设我希望输出text列少于 10 个字符。所以,我需要这个结果:
+----+------------+
| id | text |
+----+------------+
| 1 | humongous |
+----+------------+
| 1 | text goes |
+----+------------+
| 1 | here |
+----+------------+
| 2 …Run Code Online (Sandbox Code Playgroud) 我知道Files.newDirectoryStream(directory).use { ... }一旦大括号中的函数完成,就会自动关闭流。
.forEach { ... }如果我使用而不是,流也会关闭吗.use { ... }?
我试图计算两次之间有多少毫秒(例如 13:00 到 13:01 之间有 60000 毫秒)。时间由 2 个整数(小时、分钟)表示。
我写了这个函数:
public static long millisBetweenTimes(int h1, int m1, int h2, int m2) { //hour1, minute1, hour2, minute2
long millis;
millis = (h2 - h1) * (60 * 60000);
if (m < tm)
millis += (m2 - m1) * 60000;
else
millis -= (m1 - m2) * 60000;
return millis;
}
Run Code Online (Sandbox Code Playgroud)
但是,当第二次是后一天时,这将不起作用(例如周日 14:00 到周一 13:00 之间有多少毫秒?)
我需要用户当前位置的latitude,来相应地显示帖子,我正在使用 next.js 任何人都可以帮助我吗?longitude
我正在使用 IntelliJ IDEA 学习 Scala。项目 SDK 始终是 jdk-17,一切正常,直到现在。
我开始在 actor 中练习(Akka in action using Scala)。问题(如scalac:错误:编译 sbt 组件'compiler-interface-2.11.8-61.0'时出错)开始编译书籍示例。建议使用jdk1.8.0,它有帮助。我不明白为什么要使用jdk1.8.0而不是jdk-17?17 > 1.8.0?jdk1.8.0_XXX是实际的SDK吗?
构建.sbt
name := "fault-tolerance"
version := "1.0"
organization := "com.manning"
scalaVersion := "2.11.8"
libraryDependencies ++= {
val akkaVersion = "2.4.19"
Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"org.scalatest" %% "scalatest" % "3.0.0" % "test"
)
}
Run Code Online (Sandbox Code Playgroud) 当我看到它有效时,我感到非常惊讶。请解释原因
https://github.com/bethrobson/Head-First-Java/blob/master/chap12/MiniMusicPlayer3.java
public void setUpGui() { // <------- it is not static
ml = new MyDrawPanel();
f.setContentPane(ml);
f.setBounds(30, 30, 300, 300);
f.setVisible(true);
}
public void go() {
setUpGui(); // <--- call without object.setUpGui() !!!
Run Code Online (Sandbox Code Playgroud)
为什么它有效?
鉴于模除法和整数除法密切相关,您可能会认为在一次操作中获取这两个值是有意义的。有没有具有这种功能的语言?
后续问题:对于不具备此功能的语言,是否最好通过减去除法 * 分母的结果来计算模数?
// In java, if I want both values I need to do this:
int myNumber = 125;
int denominator = 6;
int division = myNumber / denominator; // 20
int modulo1 = myNumber % denominator; // 5
// Follow up: Is this a more efficient way to compute the modulo?
int modulo2 = myNumber - division * denominator;
Run Code Online (Sandbox Code Playgroud) 我刚刚了解Java流。可以通过在 Collection 上调用 .stream() 来创建流,然后您可以使用docs中描述的方法对该流进行操作。
我不明白的是这个过程实际发生在哪里。我的意思是我可以创建一个具有年龄属性的 Person 对象流并按如下方式对其进行排序:
Person john = new Person(30);
Person anne = new Person(25);
Person bill = new Person(52);
ArrayList<Person> people = new ArrayList<Person>();
people.add(john);
people.add(anne);
people.add(bill);
ArrayList<Person> sortedPeople = people
.stream()
.sorted(Comparators.comparing(person -> person.getAge()))
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
Run Code Online (Sandbox Code Playgroud)
但在我发现的文档和源代码中,函数式接口(例如包含排序方法的函数式接口)没有排序代码,仅描述传递给它的 lambda 函数。我在这里严重误解了什么吗?
java ×6
android ×1
geolocation ×1
java-stream ×1
kotlin ×1
next.js ×1
performance ×1
reactjs ×1
scala ×1
spring-boot ×1
sql ×1
userlocation ×1