我需要为ThreadLocal最终运行特定CompletableFuture.supplyAsync供应商的所有线程提供一个。
从javadoc中,我看到CompletableFuture使用“ ForkJoinPool commonPool()”非常适合我的性能用例。
如何将ThreadLocal(然后删除)转移到运行特定CompletableFuture供应商的所有池线程?
备注:
我看到所有CompletableFuture async完成方法都接受执行程序。我想使用默认值,ForkJoinPool commonPool()但是如果无法实现,我想我必须重写ThreadPoolExecutor并实现beforeExecute吗?
我有以下代码:
HttpContext httpContext = HttpContext.Current;
RequestContext currentContext = RequestContextManager.CurrentContext;
ILifetimeScope currentSessionScope = PlatformContext.LifeTimeScope;
ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>();
ConcurrentBag<ParallelCalculateObj> forEachResult = new ConcurrentBag<ParallelCalculateObj>();
ConcurrentBag<ParallelCalculateObj> testForEachPassResult = new ConcurrentBag<ParallelCalculateObj>();
ParallelLoopResult loopResult = Parallel.ForEach(applications, () =>
{
HttpContext.Current = httpContext;
RequestContextManager.SetCustomCurrentContext(currentContext);
PlatformContext.LifeTimeScope = currentSessionScope;
return new ParallelCalculateObj();
}, (application, pls, localObj) =>
{
try
{
// some code
}
catch (Exception e)
{
exceptions.Enqueue(e);
}
testForEachPassResult.Add(localObj);
return localObj;
}, forEachResult.Add);
Run Code Online (Sandbox Code Playgroud)
哪里applications.Count = 3.上面的代码执行后,我得到了forEachResult.Count = 2和testForEachPassResult.Count = 3 …
我有一组定义为' ButtonGroup bg1;'使用' javax.swing.ButtonGroup'包的单选按钮.我想禁用此组,以便用户在单击"确定"按钮后无法更改其选择btnOK.
所以我一直在寻找这些方面的东西:
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {
bg1.setEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)
但是,.setEnabled(false)似乎并不存在.
我使用jdk 1.7,jekins,maven,当我构建项目时,单元测试失败,错误是:
java.lang.VerifyError:在分支目标处期望堆栈映射表73异常详细信息:Location:com/DataDictDao.save(Lcom/DataDict;)Ljava/lang/Long; @ 25:ldc原因:此位置的预期堆栈图帧.字节代码:0000000:033d 2:11最强音FF3E 1212 1100 25b8 0018 2ab4 0000010:0022 122D B900 3302 0012 1211 0027 B800 0000020:182A B400 352B B900 3A02 0012 1211 0028 0000030:B800 182A B400 2212 3cb9 0033 0200 1212 0000040:1100 2cb8 0018 A700 2D12 1211 0029 B800 0000050:183A 0412 1211 002A B800 182A B400 2212 0000060:3e19 04b9 0042 0300 1212 1100 2bb8 0018 0000070:1904 BF12 1211架002D B800 182B B600 48b8 0000080:004E B0异常处理程序表:BCI [25,62] =>处理程序: 73 Stackmap表:same_locals_1_stack_item_extended(@ 81,Object [#43])same_frame(@ 123)
at java.lang.Class.getDeclaredConstructors0(Native Method)at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)at java.lang.Class.getDeclaredConstructors(Class.java:1901)at …
无论焦点在哪里(只要他们正在使用应用程序),我如何确定用户按下了什么键?
例如,他们按“ CTRL+ Q”(退出),程序无论如何都会退出。
通常我必须转到 KeyDown 的表单事件,并在那里设置该条件。但是如果表单没有被聚焦呢?那么CTRL+Q就行不通了。
如何在 Windows 窗体应用程序中执行此操作?我确定这很简单,但找不到方法。
根据Microsoft对The ReadLines和ReadAllLinesmethods 的解释,当您使用时ReadLines,您可以在返回整个集合之前开始枚举字符串集合.使用时ReadAllLines,必须等待返回整个字符串数组,然后才能访问该数组.因此,当您使用非常大的文件时,ReadLines可以更高效.
当他们说:
1 - "当你使用ReadLines时,你可以在返回整个集合之前开始枚举字符串集合. "如果编写下面的代码行,那么这不意味着ReadLines方法执行结束并且整个集合是返回并存储在变量filedata中?
IEnumerable<String> filedata = File.ReadLines(fileWithPath)
Run Code Online (Sandbox Code Playgroud)
2 - "当你使用时ReadAllLines,你必须等待返回整个字符串数组才能访问数组 ".这是否意味着,在下面的代码片段中,如果读取一个大文件,那么如果在读取文件后立即使用数组变量hugeFileData将不会拥有所有数据?
string[] hugeFileData = File.ReadAllLines(path)
string i = hugeFileData[hugeFileData.length-1];
Run Code Online (Sandbox Code Playgroud)
3 - "当您使用非常大的文件时,ReadLines可以更高效 ".如果是这样,那么在读取大文件时,以下代码是否有效?我相信第二行和第三行下面的代码会读取文件两次,如果我错了,请纠正我.
string fileWithPath = "some large sized file path";
string lastLine = File.ReadLines(fileWithPath).Last();
int totalLines = File.ReadLines(fileWithPath).Count();
Run Code Online (Sandbox Code Playgroud)
在上面的代码片段中两次在同一文件上调用ReadLines的原因是当我尝试下面的代码时,我TextReader在下面的代码片段的第3行上得到了一个异常"无法从关闭状态读取".
IEnumerable<String> filedata = File.ReadLines(fileWithPath);
string lastLine = filedata.Last();
int totalLines = filedata.Count();
Run Code Online (Sandbox Code Playgroud) 我再也无法部署我的天蓝色webrole,它无限循环.所以我穿上了Intellitrace,我发现了这个异常:
异常:抛出:"由于以下异常,无法加载角色入口点: - System.IO.FileLoadException:无法加载文件或程序集'System.Web.Http,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配.(HRESULT的异常:0x80131040)
在我的项目中,web.config和包(Webapi,webhost等)都在5.2.0.0中,所以我不明白为什么Azure试图找到5.0.0.0?
例:
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
你有什么主意吗 ?谢谢
ps:System.Web.Http得到copy local:true
我想停止显示器以停止睡眠(这是由公司政策驱动的)。以下是我为此使用的代码
while (true)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
Cursor.Clip = new Rectangle(this.Location, this.Size);
System.Threading.Thread.Sleep(2000);
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X + 50, Cursor.Position.Y + 50);
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
Run Code Online (Sandbox Code Playgroud)
我可以看到没有While循环的鼠标移动。但是当它只移动鼠标一次,然后限制鼠标向右移动时。
有什么更好的方法吗?
Option Explicit Off在Visual Basic .NET 中使用有什么优点吗?如果它是Off,它允许使用变量而不声明.
以下是示例代码Option Explicit Off:
Option Explicit Off
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
i = 1
MsgBox(i)
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
它工作得很好.
应该使用吗?它在任何特定情况下都有用吗?
如何在HTML文档中强制使用空白页?我有一个标题页,之后是强制分页符(以下规则)。问题是剩余的内容直接出现在下一页上,我希望标题页面和剩余的内容被1个空白页面所分割(如下图所示)。
HTML:
<div class=title-page">
title
</div>
<div class="content">
blah blah
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.title-page {
page-break-after: always;
}
Run Code Online (Sandbox Code Playgroud)
预期结果:
<div class=title-page">
title
</div>
<div class="content">
blah blah
</div>
Run Code Online (Sandbox Code Playgroud)
我知道可以在标题页和其余内容之间插入一个空白,然后对其page-break-after: always;进行窥视。不过,插入空div在语义上不太正确。有没有办法仅使用CSS来达到相同的结果?
编辑:在这种情况下,也可以用完成page-break-after: left;,因为默认情况下第一页是左页。那么在文档中间的情况下,您无法确定所在页面是左还是右。或者,当您要插入1个以上的空白页面时。还能用CSS完成吗?