小编Pec*_*tum的帖子

Java - 有没有理由检查单例是否为空两次?

我遇到了一些代码,开发人员不断检查单例是否为嵌套if的两次 - 如下面的代码中所示:

private static processManager singleton = null;
Run Code Online (Sandbox Code Playgroud)

...

public synchronized static processManager getInsatnce() throws Exception {

    if(singleton == null) {
      if(singleton == null){
             singleton = new processManager();
       }
     }
     return singleton
}
Run Code Online (Sandbox Code Playgroud)

我看不出这可能是什么原因,但代码中有很多实例,所以认为可能有原因?

java concurrency singleton multithreading

7
推荐指数
2
解决办法
1763
查看次数

Cosmos DB 中的重试策略

我想了解如何最好地为 Cosmos db (documentdb) 实施重试/退避策略。我知道 sdk 中内置了一些默认的重试机制,我可以像这样在 connectionpolicy 中进行更改:

RetryOptions = new RetryOptions() { MaxRetryAttemptsOnThrottledRequests = 3, MaxRetryWaitTimeInSeconds = 60 }
Run Code Online (Sandbox Code Playgroud)

但是,我不确定这会如何影响我应该如何进行异常管理。

目前我正在做以下事情:

GetAsync<T>(Uri, Id) {

    try {

        ResourceResponse<Document> response = await client.ReadDocumentAsync(URiFactory.CreateDocumentUri(uri), new RequestOptions { PartitionKey = new PartitonKey(convert.ToInt64(id)) }).ConfigureAwait(false); 

    }
    catch(DocumentClientException ex) {
        if(ex.StatusCode == (HttpStatusCode)TooManyRequests) {
            await Task.Run(async () =>
            {
                await Task.Delay(ex.RetryAfter);
                return await GetAsync<T>(Uri, Id).ConfigureAwait(false);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要重试吗?如果我捕捉到异常是否会停止默认的重试尝试?另外,默认的重试尝试捕获的是什么?即它只是429?如果是这样,我是否需要手动处理错误代码 449?

c# azure azure-cosmosdb

7
推荐指数
1
解决办法
6272
查看次数

对于单例模式使用双重检查锁定习语是否最佳?

对于单例模式,使用双重检查锁定习惯是否更好?还是同步方法?

即:

private static volatile ProcessManager singleton = null;

public static ProcessManager getInstance() throws Exception {

    if (singleton == null) {
       synchronized (MyClass.class) {
          if (singleton == null) {
               singleton = new ProcessManager();
         }
      }
   }
   return singleton;
Run Code Online (Sandbox Code Playgroud)

}

要么

private static processManager singleton = null;

public synchronized static processManager getInsatnce() throws Exception {

   if(singleton == null) {
            singleton = new processManager();
    }

    return singleton
 }
Run Code Online (Sandbox Code Playgroud)

java singleton synchronization locking

6
推荐指数
2
解决办法
1047
查看次数

如何在VS2012中更改"许可给"用户

我试图改变VS2012启动屏幕上显示的用户旁边的"行货" - 它的OCD的事情.

我在使用VS2012 Professional的Windows 8 Pro上.

我在网上找到了一些帮助,告诉我:

Open Registry Editor (Start->Run->type “regedit”->press enter)
Find the following key: HKCU\Software\Microsoft\VisualStudio\11.0_Config\Registration\UserName
Change it’s value to the desired name
Navigate to the following folder: C:\Users\{YOUR_USER}\AppData\Roaming\Microsoft\VisualStudio\11.0 (replace the placeholder with your own username)
Delete the file vs000223.dat – this is actually a JPG file containing the splash screen, you can change it’s name to see it for yourself
Start Visual Studio, and it magically recreates the file with the modified name in it!
Run Code Online (Sandbox Code Playgroud)

所以我按照这些步骤,并更改注册表键(包括在Windows …

visual-studio visual-studio-2012

6
推荐指数
1
解决办法
3943
查看次数

在Azure Functions上部署节点应用程序

我想知道如何在Azure Functions上部署Node.js应用程序.

基本上,我有一个功能设置并运行一个基本的hello world http示例,如下所示:

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: "Hello " + req.params.name
    };
    context.done();
};
Run Code Online (Sandbox Code Playgroud)

我试图部署到一个函数的应用程序是一个使用swagger的简单moc客户端(基本上接受请求并返回一些xml).app.js看起来像:

const SwaggerExpress = require('swagger-express-mw');
const app = require('express')();
const compression = require('compression');

const configSwagger = {
    appRoot: __dirname, // required config
};


SwaggerExpress.create(configSwagger, (err, swaggerExpress) => {
    if (err) {
        throw err;
    }

    // install middleware
    swaggerExpress.register(app);

    // server configuration
    const serverPort …
Run Code Online (Sandbox Code Playgroud)

azure node.js azure-node-sdk azure-webjobs azure-functions

5
推荐指数
1
解决办法
1638
查看次数

.Net MVC如何向各个视图添加脚本

我想知道如果我使用包装.cshtml文件,是否有办法将JavaScript文件添加到各个视图.

基本上我有一个包装器cshtml文件_Layout,我正在使用我的所有前端视图.它基本上有<header>我的标题/导航和页脚的部分和HTML.它还包含对页脚后每页上所需的所有JavaScript文件的引用.

但是,在我的联系人视图中,我想使用另一个JavaScript文件,但我不想将其添加到包装器中,因为它会将其添加到每个视图中.

无论如何使用条件语句将文件添加到包装器 - 即如果Contact视图然后引用联系人JS文件?

javascript c# asp.net asp.net-mvc razor

4
推荐指数
1
解决办法
3899
查看次数

将文本和图像放在列表项中的同一行 - html/css

我想知道是否有人能帮助我解决我遇到的一个小的html/css问题.基本上,我正在尝试使用不同的图像为每个列表项的项目创建一个无序列表,并在同一行的右侧显示文本.更具体地说,顶行的标题和下面的一些普通文本.目前,我可以将图像和文本放在同一行:-(这是我的代码.

任何帮助将不胜感激.

HTML:

<ul>
    <li class="service-list">
        <a href=""><img src="image.png" alt="icon" class="alignnone size-full wp-image-156" /></a>
        <h3>Header</h3>
        <p>
        text goes here
        </P>
    </li>
....
</ul>
Run Code Online (Sandbox Code Playgroud)

CSS:

.service-list {
    list-style-type: none;
    margin-left:0px;
    padding-left:0px;
    float: left;
    display: inline-block;
}


.service-list p {
    text-align: right; 
    margin: 0; 
    padding: 0;
}
Run Code Online (Sandbox Code Playgroud)

html css list css3 html-lists

3
推荐指数
1
解决办法
7万
查看次数

shell bash,你能检查一个函数是否存在

我想知道是否有可能检查脚本中是否存在函数.就在这一刻,我有一些if if来检查一个值,然后调用一个函数,但是想知道是否有可能做类似的事情:

if[[ ${function_name}Function exists ]]
then
.....call function etc
fi
Run Code Online (Sandbox Code Playgroud)

脚本中可能有一个函数

这可能吗?

string bash shell grep function

3
推荐指数
1
解决办法
1698
查看次数

.Net MVC4重定向到操作不按预期工作

这可能是一个愚蠢的问题,但似乎RedirectToAction()无法正常工作.

我有一个管理控制器作为一个单独的区域完成,我有一个注销任务方法,我只是试图让方法在注销时重定向到网站索引,但它将我带到管理路由下的网址而不是我不知道为什么我在调用方法时给它控制器名称和操作方法名称在控制器内.相反它需要我: http:// localhost:63374/Admin/Home

有什么我做错了吗?

        [Route("logout")]
    public async Task<ActionResult> Logout()
    {
        var authManager = HttpContext.GetOwinContext().Authentication;

        authManager.SignOut();

        return RedirectToAction("index", "home");
    }
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net asp.net-mvc asp.net-mvc-4

3
推荐指数
1
解决办法
2397
查看次数

wordpress,获取自定义帖子类型的类别名称

有没有更好的方法来获取wordpress中自定义帖子类型的类别名称?

<?php        // get the portfolio categories
            $terms = get_the_terms( $post->ID, 'filters' );                           
            if ( $terms && ! is_wp_error( $terms ) ) : 
                $names = array();
                $slugs = array();
                foreach ( $terms as $term ) {
                 $names[] = $term->name;
                 $slugs[] =  $term->slug;
                }                                
                $name_list = join( " / ", $names );
                $slug_list = join( " category-", $slugs );
        endif;
    ?>


    <!-- BEGIN portfolio-item-->
    <li class="portfolio-item third column category-<?php echo $slug_list; ?>" data-filter="category-<?php echo $slug_list; ?>">
Run Code Online (Sandbox Code Playgroud)

html css php wordpress

2
推荐指数
1
解决办法
3万
查看次数