我有一个列表,其中包含要为每个像素计算的数据(例如,列表大小= 1024x768).现在我想在列表中迭代多线程并保存HashMap中每个像素的计算.但无论我做什么,我都无法做到这一点.我尝试了几种方法,我的最后一种是这样的:
ConcurrentMap<T, Color> map = new ConcurrentHashMap<T, Color>();
ExecutorService pool = Executors.newFixedThreadPool(4);
Iterator<T> it = camera.iterator();
while (it.hasNext()) {
Runnable run = () -> {
int i = 0;
while (it.hasNext() && i < 1000) {
i++;
T cameraRay = it.next();
if (object.collide(cameraRay.getRay()) == null)
map.put(cameraRay, BG_COLOR);
else
map.put(cameraRay, this.shader.shade(cameraRay.getRay(), object.collide(cameraRay.getRay())).getColor());
}
};
pool.execute(run);
}
pool.shutdown();
try {
if (pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)) {
System.out.println("Mapsize: " + map.size());
// Draw Image:
map.forEach((ray, color) -> {image.setColor(ray, color);});
}
} catch (InterruptedException e) …Run Code Online (Sandbox Code Playgroud) 我读到了将包含潜在安全风险的php文件存储在根目录之外的好习惯.
现在我有php文件包含处理注册/登录的东西.这些都在根目录之外.现在我通过jquery捕获表单内容并将其发送到此php文件.
但这似乎不可能与js/jquery:
$.ajax({
type: "POST",
url: "../php_includes/register.inc.php", //beyond root path
data: data,
})
.done(function(data, status) {
//...
});
Run Code Online (Sandbox Code Playgroud)
我有设计错误或只是做错了吗?
什么是"最佳实践"解决方案?