我正在使用这种方法将数据存储在托管http服务器的全局数组中,其中某些请求将操纵全局数组.
我有点担心遇到某些操作的线程问题 - 主要是push和splice.我想如果一个请求让我迭代数组并根据条件删除项目,而另一个请求让我调用.push()数组,我将遇到问题.谁能证实这一点?
我主要用C#编写,即使是一个简单的增量也不是线程安全的(启动25个执行i ++的线程,并不能保证i == 25毕竟说完了).
更新:
我写了5个例子来证明我在说什么.测试1和测试3工作正常.测试2失败,因为...通常会被称为线程问题(无论它们是否是实际的CPU线程).测试4和5,当并行运行时似乎工作(意味着它们没有像测试2那样的碰撞问题).
我正在使用ApacheBench进行测试,生成1000个并行请求.
这让我相信测试1和测试3工作正常,因为nodejs不会并行执行并行 javascript函数中的多个(阻塞?).一旦实现了setInterval/setTimeout,它就会释放nodejs来执行另一个回调实例(非阻塞?).app.get('/test3'...)回调实例
我真的只是想了解它到底non-blocking I/O model意味着什么.这是否意味着"嘿,如果你需要非阻塞,可以用setTimeout和setInterval进行非阻塞,否则我们将阻止任何其他外层函数运行,直到我们耗尽我们正在使用的函数" ?我觉得有必要知道这一点,这样我就不会陷入困境,以为我可以实现像/ test2这样的东西并且完全安全.
另外如果我试图用我的回调进行非阻塞,我真的应该打电话setTimeout(code, 1)吗?或者,还有更好的方法?
更新这可能已经修复:http://entityframework.codeplex.com/workitem/486
...
针对我的实体的相当简单的LINQ语句导致不必要的复杂SQL.更多相关内容,这是设置:
表
出版物
收据
LINQ
var query = from r in context.Receipts.Include("Publication")
where r.DateInserted < lagDate
&& r.ReceiptId > request.AfterReceiptId
&& r.Publication.TopicId == topicEntity.TopicId
&& r.Publication.ReceiptCount > 1
select r;
Run Code Online (Sandbox Code Playgroud)
SQL
exec sp_executesql N'SELECT TOP (25)
[Project1].[ReceiptId] AS [ReceiptId],
[Project1].[PublicationId] AS [PublicationId],
[Project1].[DateInserted] AS [DateInserted],
[Project1].[DateReceived] AS [DateReceived],
[Project1].[PublicationId1] AS [PublicationId1],
[Project1].[PayloadId] AS [PayloadId],
[Project1].[TopicId] AS [TopicId],
[Project1].[BrokerType] AS [BrokerType],
[Project1].[DateInserted1] AS [DateInserted1],
[Project1].[DateProcessed] AS [DateProcessed],
[Project1].[DateUpdated] …Run Code Online (Sandbox Code Playgroud) 我想在连接太多用户或从不受支持的域连接时向客户端提供有意义的错误,所以...
我写了一些WebSocket服务器代码:
var http = require('http');
var httpServer = http.createServer(function (request, response)
{
// i see this if i hit http://localhost:8001/
response.end('go away');
});
httpServer.listen(8001);
// https://github.com/Worlize/WebSocket-Node/wiki/Documentation
var webSocket = require('websocket');
var webSocketServer = new webSocket.server({ 'httpServer': httpServer });
webSocketServer.on('request', function (request)
{
var connection = request.reject(102, 'gtfo');
});
Run Code Online (Sandbox Code Playgroud)
还有一些WebSocket客户端代码:
var connection = new WebSocket('ws://127.0.0.1:8001');
connection.onopen = function (openEvent)
{
alert('onopen');
console.log(openEvent);
};
connection.onclose = function (closeEvent)
{
alert('onclose');
console.log(closeEvent);
}
connection.onerror = function (errorEvent)
{
alert('onerror');
console.log(errorEvent);
};
connection.onmessage …Run Code Online (Sandbox Code Playgroud) 失败:
object o = ((1==2) ? 1 : "test");
Run Code Online (Sandbox Code Playgroud)
成功:
object o;
if (1 == 2)
{
o = 1;
}
else
{
o = "test";
}
Run Code Online (Sandbox Code Playgroud)
第一个语句中的错误是:
无法确定条件表达式的类型,因为'int'和'string'之间没有隐式转换.
为什么需要这样,我将这些值分配给object类型的变量.
编辑:上面的例子是微不足道的,是的,但有一些例子,这将是非常有用的:
int? subscriptionID; // comes in as a parameter
EntityParameter p1 = new EntityParameter("SubscriptionID", DbType.Int32)
{
Value = ((subscriptionID == null) ? DBNull.Value : subscriptionID),
}
Run Code Online (Sandbox Code Playgroud) 我已经成功创建了一个在不使用身份验证时正常工作的WS客户端.
但是,服务器(WebSphere)现在需要添加一个ws-security用户名令牌,而我很难做到这一点.生成的SOAP消息应该看起来像这样:
<soapenv:Envelope
xmlns:ns="http://foo.bar/1.0"
xmlns:ns1="http://www.witsml.org/schemas/140"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>foo</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bar</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">foooooobar==</wsse:Nonce>
<wsu:Created>2010-01-25T13:09:24.860Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ns:fooBar>...</ns:fooBar>
</soapenv:Body>
Run Code Online (Sandbox Code Playgroud)
我已经下载并安装了Microsoft的WSE 3.0 SDK,并在我的Visual Studio 2005项目中添加了对DLL的引用.
我现在可以访问Microsoft.Web.Services3.*命名空间,但我目前难以理解如何继续.
客户端代码是由Web引用自动生成的,因此我只做了少量工作就将消息发送到未经身份验证的服务器:
WS.FooResultHttpService ws = new WS.FooResultHttpService();
ws.Url = "http://foo.bar.baz";
ws.SendSomething(message);
Run Code Online (Sandbox Code Playgroud)
我刚开始调查使用Microsoft.Web.Services3.Security.Tokens.UsernameTokenManager,但到目前为止,我还没有能够得到任何东西.
任何提示将不胜感激,因为我似乎无法在网上找到任何好的食谱.
谢谢!
我很难尝试将简单的可点击标记添加到ArcGIS,纯粹使用JavaScript进行地图绘制.所有ArcGIS Samples似乎都从服务器获取其标记和相关的弹出信息. 如何使用ArcGIS获得与下面的Google Maps示例代码相同的结果?
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="map" style="width: 500px; height: 500px;"></div>
<script type="text/javascript">
window.onload = function() {
var myOptions = {
zoom: 2,
center: new google.maps.LatLng(40, -75),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var icon = new google.maps.MarkerImage("http://cinnamonthoughts.org/wp-content/uploads/2010/01/Custom-Marker-Avatar.png");
var markerOptions = {
icon: icon,
map: map,
position: new google.maps.LatLng(37.7699298, -122.4469157),
};
var marker = new google.maps.Marker(markerOptions);
google.maps.event.addListener(marker, 'click', function() {
var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent("hello world");
infoWindow.open(map, marker);
});
};
</script>
Run Code Online (Sandbox Code Playgroud) Chrome的array.map工作正常,但jQuery .map以某种方式生成循环引用.我看不到任何使用循环引用的证据console.log,但JSON.stringify会抛出Uncaught TypeError: Converting circular structure to JSON第二个块.
在JSFiddle上运行它:http://jsfiddle.net/langdonx/vQBak/
或者检查代码:
var callback = function(index, element) {
return {
"index": index
};
};
var array1 = ["1", "2"];
var mappedArray1 = array1.map(callback);
console.log(mappedArray1);
var json1 = JSON.stringify(mappedArray1);
console.log(json1);
var jqueryArray2 = $('body > div');
var mappedArray2 = jqueryArray2.map(callback);
console.log(mappedArray2);
var json2 = JSON.stringify(mappedArray2); // Chokes with "Uncaught TypeError: Converting circular structure to JSON"
console.log(json2);?
Run Code Online (Sandbox Code Playgroud)
是的,我正在使用相同的回调,是的ECMAScript map以不同的顺序传递参数,但这个例子无关紧要,因为它们都是简单类型(字符串,数字).
看起来很简单,但我不能从我的指令中获得$ event.当test被调用时cb-click,$event是未定义的,但在指令之外(通过html),它是事件对象.
如果我使用链接功能(不包括在我的小提琴中),我可以得到$event,但我不能$ parse/$ eval它在正确的范围内.
http://jsfiddle.net/langdonx/KgcGY/
<div ng-app="app" ng-controller="x">
<!-- via directive -->
<checkbox cb-model="y" cb-click="test($event, b)"></checkbox>
<!-- via html -->
<div><input id="c2" type="checkbox" ng-model="x" ng-click="test($event, 'a')"> <label for="c2">{{x}}</label></div>
</div>
Run Code Online (Sandbox Code Playgroud)
-
var app = angular.module('app', []);
app.directive('checkbox', function ($parse) {
return {
restrict: 'E',
replace: true,
scope: {
cbModel: '=',
cbClick: '&'
},
template: '<div><input id="c1" type="checkbox" ng-model="cbModel" ng-click="cbClick($event, \'a\')"> <label for="c1">{{cbModel}}</label></div>'
};
});
app.controller('x', function x($scope) {
$scope.x = true;
$scope.y …Run Code Online (Sandbox Code Playgroud) 我想使用Angular的breadcrumb功能.我将此javascript文件添加到我的services文件夹中.
我在header.html文件中添加了一个div来调用javascript.根据Angular的说法,div应该如下所示:
<div>
<ul class="breadcrumb">
<li ng-repeat="breadcrumb in breadcrumbs.getAll()">
<span class="divider">/</span>
<ng-switch on="$last">
<span ng-switch-when="true">{{breadcrumb.name}}</span>
<span ng-switch-default><a href="{{breadcrumb.path}}">{{breadcrumb.name}}</a></span>
</ng-switch>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
正在创建div,当我检查它时,我看到了
<!-- ngRepeat: breadcrumb in breadcrumbs.getAll() -->
但没有面包屑.有任何想法吗?
为什么允许这样做?当你继承使用这个范例的代码时,这是非常令人困惑的...特别是当所述代码甚至不打扰官方声明公共属性时,而是用一些随机方法设置它.有没有办法防止它(更改设置,使用某些关键字或使用界面)?
class Collision
{
public $Sort = "sort property";
public function Sort()
{
print 'sort function called<br/>';
return 'sort function return';
}
}
$a = new Collision();
print $a->Sort . '<br/>';
print $a->Sort() . '<br/>';
Run Code Online (Sandbox Code Playgroud)
输出:
sort property
sort function called
sort function return
Run Code Online (Sandbox Code Playgroud) javascript ×3
angularjs ×2
c# ×2
node.js ×2
arcgis ×1
breadcrumbs ×1
google-maps ×1
jquery ×1
linq ×1
oop ×1
php ×1
web-services ×1
websocket ×1
ws-security ×1
wse3.0 ×1