在bash中,有时我会有很长的命令,我需要编辑一些单词.现在我使用End/Home来移动命令的结束/开始,但是如果我必须移动说x行中的字符怎么办?
我需要类似于xb/xw的VI,但我需要移动字符而不是单词.
我的主线程中有一个函数,它会将一些数据写入磁盘.我不希望我的主线程卡住(磁盘I/O的高延迟)并且创建一个新线程只是为了写入是一个矫枉过正.我决定使用ExecutorService.
ExecutorService executorService = Executors.newFixedThreadPool(3);
Future future = executorService.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
logger.log(Level.INFO, "Writing data to disk");
return writeToDisk();
}
});
Run Code Online (Sandbox Code Playgroud)
writeToDisk是写入磁盘的函数
这是一个很好的方式吗?有人可以提出更好的方法吗?
更新:数据大小将大于100 MB.磁盘带宽为40 MBps,因此写入操作可能需要几秒钟.我不希望调用函数卡住,因为它必须做其他工作,所以,我正在寻找一种方法来调度磁盘I/O异步执行调用线程.
我需要委派任务而忘记它!
我需要redis 中匹配给定模式的所有键: *_xyz_*,然后我通过以下python代码获取它们的所有值:-
def get_keys(self,pattern):
self.r_prod.keys(pattern);
keys = self.r_prod.execute();
for i in keys[0]:
self.r_prod.get(i);
return self.r_prod.execute();
Run Code Online (Sandbox Code Playgroud)
现在keys将所有内容都保存在内存中是相当大的。所以,我想知道有没有办法分页键调用一定的限制?
版本:Matlab 2009a
我正在使用randsrc()函数生成大小<1x116286>的向量.由于我再次将它添加到相同大小但uint8类型的矩阵中,我的做法如下 -
l=typecast(randsrc(1,v(2)),'uint8');
Run Code Online (Sandbox Code Playgroud)
现在,Matlab已经更改了返回的元素向量 - [240,63,0]而不是[-1,1],大小为<1x930288 uint8>.这是双倍的,uint8有不同的大小,但是我希望在类型转换后使用相同大小和值的向量.
PS:我想在大小<1x116286>的矩阵上从所有trhe值中减去或加"1".有没有其他巧妙的方法来做到这一点?
tl; dr:在Java中,更好的是,每次重用容器对象或创建对象,让垃圾收集器完成工作
我正在处理Java中的大量数据,我经常使用以下类型的代码结构: -
版本1:
for(...){//outer loop
HashSet<Integer> test = new HashSet<>(); //Some container
for(...){
//Inner loop working on the above container Data Structure
}
//More operation on the container defined above
}//Outer loop ends
Run Code Online (Sandbox Code Playgroud)
在这里,我每次在循环中分配新内存,并在再次分配空内存之前在内部/外部循环中执行一些操作.
现在我担心Java中的内存泄漏.我知道Java有一个相当不错的垃圾收集器,但我应该修改我的代码而不是依赖它,如下:
版本2:
HashSet<Integer> test = null;
for(...){//outer loop
if(test == null){
test = new HashSet<>(); //Some container
}else{
test.clear()
}
for(...){
//Inner loop working on the above container Data Structure
}
//More operation on the container defined above
}//Outer loop ends
Run Code Online (Sandbox Code Playgroud)
我有三个问题: - …
我得到的一些JSON数据在键名中有空格.我正在使用标准encoding/json库来解组数据.但是,它无法理解模式中带空格的键.例如以下代码:
package main
import (
"encoding/json"
"fmt"
)
func main() {
var jsonBlob = []byte(`[
{"Na me": "Platypus", "Order": "Monotremata"},
{"Na me": "Quoll", "Order": "Dasyuromorphia"}
]`)
type Animal struct {
Name string `json: "Na me"`
Order string `json: "Order,omitempty"`
}
var animals []Animal
err := json.Unmarshal(jsonBlob, &animals)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v", animals)
}
Run Code Online (Sandbox Code Playgroud)
输出为:
[{Name: Order:Monotremata} {Name: Order:Dasyuromorphia}]
Run Code Online (Sandbox Code Playgroud)
所以在模式中,库移除了空间(来自Na me)并尝试找到键(Name),这显然不存在.有什么建议我可以在这做什么?
如果我创建一个虚拟线程的执行器服务
Executors.newVirtualThreadPerTaskExecutor()
Run Code Online (Sandbox Code Playgroud)
据我所知,每个任务都在虚拟线程上运行。这些虚拟线程通过平台线程进行调度(希望是交错的)。
这里使用了多少个平台线程?我没有看到任何其他 API 来指定我想要的线程数。我在 Macbook M1 Pro 上使用 Java 21 运行它。
我有4个观察者正在监听可观察的数据.然而,我的一个观察者是较慢的,可以采取.我刚看到notifyObserver的代码为: -
132 public void notifyObservers(Object arg) {
133 /*
134 * a temporary array buffer, used as a snapshot of the state of
135 * current Observers.
136 */
137 Object[] arrLocal;
138
139 synchronized (this) {
/**comment removed for clarity **/
152 if (!changed)
153 return;
154 arrLocal = obs.toArray();
155 clearChanged();
156 }
157
158 for (int i = arrLocal.length-1; i>=0; i--)
159 ((Observer)arrLocal[i]).update(this, arg);
160 }
Run Code Online (Sandbox Code Playgroud)
从代码中可以清楚地看到观察者是一个接一个地被调用的.由于设计观察者在执行中是独立的.不应该同时调用它们arg作为最终的功能吗?
执行的时间本t1+t2+t3+t4应该是max(t1,t2,t3,t4).我可以使 …
java concurrency design-patterns java.util.concurrent observer-pattern