HttpClient共享连接管理器

时间:2016-10-20 04:48:59

标签: apache-httpclient-4.x

环境:HttpClient 4.4。

在HttpClientBuilder类中,我可以看到以下代码,

#include <stdio.h>
#include <unistd.h>

#define COMMAND_SIZE 4096

int main(int argc, char **argv) {
  char cat[] = "cat ";
  char *command;
  char *commandRepeat;
  size_t commandLength;

  commandLength = strlen(cat) + strlen(argv[1]) + 1;
  command = (char *) malloc(commandLength);
  strncpy(command, cat, commandLength);
  strncat(command, argv[1], (commandLength - strlen(cat)) );

  // Search command string for ';'
  while(strchr(command, ';') != NULL){
    // ERROR, ask for filename again.
    // Use temporary buffer for user input
    commandRepeat = (char *) malloc(COMMAND_SIZE);
    printf("You used an invalid character ';'\nPlease enter the filename again: ");
    fgets(commandRepeat, COMMAND_SIZE, stdin);
    // Trim newline that fgets includes
    commandRepeat[strcspn(commandRepeat, "\n")] = '\0';

    // Prepare command string
    commandLength = strlen(cat) + strlen(commandRepeat) + 1;
    free(command);
    command = (char *) malloc(commandLength);
    strncpy(command, cat, commandLength);
    strncat(command, commandRepeat, (commandLength - strlen(cat)) );
    free(commandRepeat);
  }

  printf ("This is the command->%s\n", command);
  system(command);

  return (0);
}

我无法将这两个条件联系起来。

如果您使用共享连接管理器,为什么不使用IdleConnectionEvictor?

1 个答案:

答案 0 :(得分:0)

如果一个人创建了多个HttpClient共享一个连接池的实例,那么一个人可能只希望只有IdleConnectionEvictor的实例,那么一个不是吗?当一个实例完全足够时,多个IdleConnectionEvictor争用连接池锁来驱逐空闲连接的重点是什么?