这是我进入stackoverflow世界的第一步,如果我提出任何建议,那么道歉.
我正在尝试创建一个WCF操作,它具有一个不暴露给外部世界的参数,而是自动传递给该函数.
所以全世界都看到了: int Add(int a, int b)
但它实现为: int Add(object context, int a, int b)
然后,在运行时由系统提供上下文.我正在使用的例子是完全人为的,但模仿我在现实世界中所研究的一些东西.
我能够接近,但不是那么完整.
首先,我创建了一个简单的方法并编写了一个应用程序来确认它的工作原理.确实如此.它返回一个+ b并将上下文作为字符串写入我的调试.好极了.
[OperationContract]
int Add(object context, int a, int b);
Run Code Online (Sandbox Code Playgroud)
然后我写了下面的代码:
public class SupplyContextAttribute : Attribute, IOperationBehavior
{
public void Validate(OperationDescription operationDescription)
{
if (!operationDescription.Messages.Any(m => m.Body.Parts.First().Name == "context"))
throw new FaultException("Parameter 'context' is missing.");
}
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
dispatchOperation.Invoker = new SupplyContextInvoker(dispatchOperation.Invoker);
}
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
}
public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters) …Run Code Online (Sandbox Code Playgroud) 当我尝试运行这个程序时,我收到一个奇怪的错误.该类编译成多个.class文件,我上周编译它(编辑之前)就好了.但现在,我看到了这个:
Exception in thread "main" java.lang.ClassFormatError: Extra bytes at the end of class file blah/hooplah/fubar/nonsense/IndexId$Transaction
Run Code Online (Sandbox Code Playgroud)
从我看来,Java 6 build 1.5可以修复它,因为它允许类文件末尾的额外字节(我认为),但我宁愿使用build 1.6.
我正在Windows上进行编辑,然后将.java文件FTP到OpenVMS机器上,然后编译它们.在编译之后,我将.class文件移动到一个目录中,该目录是通过爆炸前一个jar文件然后重新jar.
关于这是如何发生或如何解决的任何明确的想法?
我希望有一个子例程作为哈希的成员,该哈希能够访问其他哈希成员.
例如
sub setup {
%a = (
txt => "hello world",
print_hello => sub {
print ${txt};
})
return %a
}
my %obj = setup();
$obj{print_hello};
Run Code Online (Sandbox Code Playgroud)
理想情况下,这将输出"你好世界"
编辑
对不起,我没有指定一个要求
我应该可以做到
$obj{txt} = "goodbye";
Run Code Online (Sandbox Code Playgroud)
然后输出$ obj {print_hello} goodbye
我们有大约1.2 GB(总机物理内存2 GB)的允许的最大堆大小JBoss上运行的Web基于Java的应用程序.在某些时候,应用程序停止响应(对客户端)几分钟.经过一些分析,我们发现罪魁祸首是Full GC.以下是详细GC日志的摘录:
74477.402:[全GC [PSYoungGen:3648K-> 0K(332160K)] [PSOldGen:778476K-> 589497K(819200K)] 782124K-> 589497K(1151360K)[PSPermGen:102671K-> 102671K(171328K)],646.1546860秒] [ 时报:用户= 3.84 SYS = 3.72,实际= 646.17秒 ]
我不明白是怎么回事可能是实时花费在全GC是约11分钟(646秒),而用户+ SYS时间是7.5秒.7.5秒声音对我来说更合理的时间花在从老一代清洗<200 MB.所有其他时间去哪儿了?
非常感谢.
我有联系人的姓名,电话号码和电子邮件信息.我只想为现有联系人插入额外的电子邮件和电话.我的问题是
提前致谢.
我有一个小的UIView应该总是出现在屏幕的中央.这适用于纵向模式,但不适用于横向模式.
为了绘制UIView,我使用:
myView.frame = CGRectMake((visibleArea.size.width - MY_VIEW_WIDTH) / 2, (visibleArea.size.height - MY_VIEW_HEIGHT) / 2, MY_VIEW_WIDTH, MY_VIEW_HEIGHT);
myView.autoresizingMask = (
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin
);
Run Code Online (Sandbox Code Playgroud)
可能遗漏的任何想法?
我试图找到素数<2,000,000的总和.这是我在Java中的解决方案,但我似乎无法得到正确的答案.请对可能出现的问题提供一些意见,并对代码的一般建议表示赞赏.
打印'sum'给出:1308111344,这是不正确的.
编辑:感谢您的帮助.将int更改为long和<to <=并且它完美无缺,除了是找到素数的低效方法:)
/*
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
*/
class Helper{
public void run(){
Integer sum = 0;
for(int i = 2; i < 2000000; i++){
if(isPrime(i))
sum += i;
}
System.out.println(sum);
}
private boolean isPrime(int nr){
if(nr == 2)
return true;
else if(nr == 1)
return false;
if(nr % 2 == 0)
return false;
for(int …Run Code Online (Sandbox Code Playgroud) 我有主管的状态输出,看起来像这样.
frontend RUNNING pid 16652, uptime 2:11:17
nginx RUNNING pid 16651, uptime 2:11:17
redis RUNNING pid 16607, uptime 2:11:32
Run Code Online (Sandbox Code Playgroud)
我需要提取nginx的PID.我已经通过grep -P命令完成了它,但是在远程机器上grep是在没有perl正则表达式支持的情况下构建的.
看起来sed或awk正是我需要的,但我不熟悉它们.
请提前帮助我找一个怎么做的方法.
我正在尝试使用Pattern.split()将Java正则表达式分解为"foo"和"bar"." - "字符可能是几个短划线之一:ASCII' - ',em-dash,en-dash等.我构造了以下正则表达式:
private static final Pattern titleSegmentSeparator = Pattern.compile("\\s(\\x45|\\u8211|\\u8212|\\u8213|\\u8214)\\s");
Run Code Online (Sandbox Code Playgroud)
如果我正确地阅读Pattern文档,那么当两边都被空格包围时,它应该捕获任何unicode破折号或ascii破折号.我使用的模式如下:
String[] sectionSegments = titleSegmentSeparator.split(sectionTitle);
Run Code Online (Sandbox Code Playgroud)
没有快乐.对于下面的示例输入,未检测到破折号,titleSegmentSeparator.matcher(sectionTitle).find()返回false!
为了确保我没有遗漏任何不寻常的字符实体,我使用System.out打印一些调试信息.输出如下 - 每个字符后跟(int)char的输出,它应该是它的'unicode代码点,不是吗?
样本输入:
研究摘要(1/10) - 竞争
S(83)t(116)u(117)d(100)y(121)(32)S(83)u(117)m(109)m(109)a(97)r(114)y(121) )(32)((40)1(49)(32)o(111)f(102)(32)1(49)0(48))(41)(32) - (8211)(32)C( 67)O(111)M(109)p(112)E(101)T(116)I(105)T(116)1(105)○(111)N(110)
在我看来,破折号是代码点8211,它应该与正则表达式匹配,但事实并非如此!这里发生了什么?
我想加密/解密许多小的(2-10kB)数据.现在性能还可以:在Core2Duo上,我得到大约90 MBytes/s的AES256(当使用2个线程时).但是我可能需要在将来改进它 - 或者至少减少对CPU的影响.